Google Answers Logo
View Question
 
Q: php-mysql connect ( No Answer,   3 Comments )
Question  
Subject: php-mysql connect
Category: Computers > Programming
Asked by: hlf-ga
List Price: $10.00
Posted: 06 Mar 2003 15:30 PST
Expires: 09 Mar 2003 12:56 PST
Question ID: 172903
mysql_connect passes the parameters host, user, password
with php I wish to connect with the equivalent of the shell command

   --local-infile=1 -u user -p password

My attempts at this have all resulted in syntax errors. How can I do this?

Request for Question Clarification by joseleon-ga on 07 Mar 2003 00:25 PST
Hello:

As far as I know, you can use mysql from the shell this way:

mysql -h localhost -D test -u user -p passwrod

Do you want to connect to mysql using the shell and use that connection from PHP?

Regards

Clarification of Question by hlf-ga on 07 Mar 2003 05:07 PST
To all the commentators:

Thank you.

Yes, I wish to enter the complete logon with --local-infile=1 as part
of a PHP  command. I do not own the server therefore I cannot
recompile to allow infile. This is, as Iunderstand it, a security
issue.

Howard

Request for Question Clarification by sycophant-ga on 07 Mar 2003 17:43 PST
HI,

As I don't believe that it is possible to actually do what you are
asking, would you accept an alternative?

I can provide some PHP code that could perform the same function as
the MySQL command LOAD DATA INFILE. It may not be quite as efficent as
the MySQL command, but assuming you simply want to load the contents
of a delimited text file into a MySQL table then it should be fine.

Let me know if this would be acceptable.

Regards,
sycophant-ga

Clarification of Question by hlf-ga on 08 Mar 2003 03:17 PST
Clarification for sycophant-ga,

Thank you. The problem is that mysql has been compiled on the system
as I use to block 'load data infile' and 'load data local infile'. The
only way around this is to invoke --local-infile=1 with the login.

I do have code for PHP/MYSQL for load data infile and load data local
infile.
Thanks for the offer.

All of my research shows that PHP/MYSQL does not permit the function I
seek. I will keep this question open for another day or so to see if
any miracles happen.

Thanks again for being so responsive.

HLF

Request for Question Clarification by sycophant-ga on 08 Mar 2003 17:54 PST
Hi, 

I may not have been clear about my suggestion.

My suggestion was to not to use that command, as I realise that
functionality is not available to you, but to emulate it's function
using only standard MySQL and PHP commands, allowing you to achieve
the same end result, while not needing to use the blocked command.

This way you will be able to load the data from the file without
having to use LOAD DATA INFILE.

Would that be any help? Or do you really need to use the LOAD DATA
INFILE command to populate the table?

Regards,
sycophant-ga

Clarification of Question by hlf-ga on 09 Mar 2003 05:00 PST
You are correct. I do not need to use

Clarification of Question by hlf-ga on 09 Mar 2003 05:03 PST
You are correct. I do not need to use LOAD DATA LOCAL INFILE, but I do
need to populate an existing table structure with the contents of a
properly formatted file. If you know another way of doing this, I
would like to see it. I had thought about doing a loop with series of
INSERTS but was concerned about performance with large files.


HLF

Clarification of Question by hlf-ga on 09 Mar 2003 12:55 PST
Many thanks to all the commentors. I am going to close the question
having concluded that neither PERL nor PHP allows what I want to do so
I will work around it.

HLF
Answer  
There is no answer at this time.

Comments  
Subject: Re: php-mysql connect
From: jdog-ga on 06 Mar 2003 15:47 PST
 
I'm a little rusty, but I believe you need to use the mysql_options()
function (after you call the mysql_connect()). Something like this
should work:

$link = mysql_connect("localhost", "mysql_user", "mysql_password")
        or die("Failed: " . mysql_error());
mysql_options($link, MYSQL_OPT_LOCAL_INFILE, 1);
.
.
.
mysql_close($link);
Subject: Re: php-mysql connect
From: jdog-ga on 06 Mar 2003 16:09 PST
 
Sorry, I was wrong there. I was mixing C with PHP =D.
Subject: Re: php-mysql connect
From: sycophant-ga on 07 Mar 2003 02:59 PST
 
I can't really answer this question, because there is no way to
emulate that behaviour.

If MySQL has been comiled with --enable-local-infile=0 then you cannot
override that option with the current PHP MySQL functions, so far as I
can tell.

However, as far as I am away, you are able to remove the restrictions
by recompiling MySQL with --enable-local-infile=1.

See the following references:
http://www.mysql.com/doc/en/LOAD_DATA.html
http://www.mysql.com/doc/en/LOAD_DATA_LOCAL.html

Sorry I can't be of more help.

Regards,
sycophant-ga

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy