load data local infile

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

load data local infile

Post by bouncer »

i have some problems in this code, especially in the query, because every time that i run it in php, it always shows "Invalid DATA LOAD query".
i have run this query in mysql prompt and it run without any problem, but give me some warnings (don´t know why) the same number of warnings as the number of rows that i have in the 'out.txt'

Code: Select all

$result = mysql_db_query('$dbName',"LOAD DATA LOCAL INFILE 'out.txt' REPLACE INTO TABLE exist FIELDS TERMINATED BY ','") or die ("Invalid DATA LOAD query");
can someone help me here ?

thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

replace die ("Invalid DATA LOAD query")
by die (mysql_error())
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

thanks volka

the problem was in '$dbName', i have changed it to $dbName without ' ', and it worked, because i have declared $dbName = 'database-name'; :lol:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

btw: mysql_db_query is marked as "deprecated"
http://de3.php.net/function.mysql_db_query wrote:This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead.
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

volka wrote:btw: mysql_db_query is marked as "deprecated"
http://de3.php.net/function.mysql_db_query wrote:This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead.
thanks i have already changed it. :wink:

by the way, do you know how can i see warnings in mysql prompt i'm using 4.0.11 version of mysql in the help they say to use \W to show warnings but i use it and i continue without see warnings :? but it works just fine :wink:

Code: Select all

mysql>\W

Show warnings enable.
mysql> LOAD LOCAL DATA INFILE '/temp/out.txt' REPLACE INTO TABLE exist FIELDS TERMINATED BY ',';

bla bla bla ... and no warnings
mysql>_

thanks in advance
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

issue the statement

mysql>show warnings;

that should show you the last warning issued
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

mikeq wrote:issue the statement

mysql>show warnings;

that should show you the last warning issued
i have already use that and nothing appears :? , keeps saying that i have a error of syntax...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Does that mean bla bla bla actually stands for an error message?
If there are syntax errors you won't get warnings because the syntax error stops processing the statement before warnings may occur.
So, bla bla bla translates to ...?



you might want to check the correct syntax at http://dev.mysql.com/doc/refman/5.1/en/load-data.html
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

volka wrote:Does that mean bla bla bla actually stands for an error message?
If there are syntax errors you won't get warnings because the syntax error stops processing the statement before warnings may occur.
So, bla bla bla translates to ...?
translates to ....

Query: OK, 34574 rows affected (0.69 sec)
Records: ***** ......

thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

bouncer wrote:keeps saying that i have a error of syntax...
e ...where? Not in
bouncer wrote:Query: OK, 34574 rows affected (0.69 sec)
Records: ***** ......
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

yes, just in the end of reports
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what?
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

in the end of this:

Query: OK, 34574 rows affected (0.69 sec)
Records: ***** ......
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Ok, let me ask a question: Do you think the actual error message might help us to solve this? Yes or no?
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

no, the message only tell us to consult the mySQL manual :roll:
Post Reply