Problem executing MySQL query

Hello AGAIN :slight_smile:

this time i have this problem :

i have a query (the query is correct, it runs on mysql) and i wrote a simple php script to execute it:

[php]<?php
$mysqli=mysql_connect("…","…","…","…");
if (mysqli_connect_errno()){
printf(“connection failed”);
} else
{

mysql_select_db(“database”) or die(mysql_error());

$sql = “LOAD DATA LOCAL INFILE ‘C:/…’
REPLACE INTO TABLE table1 FIELDS TERMINATED BY ‘,’”;

$res = mysql_query($sql)or die(“there is still hope:
”.mysql_error());

echo “

”;
echo “”;
while($row = mysql_fetch_array($res)){
echo “
Result
”;
echo $row[‘name’];
echo “
”;

}
}
?>[/php]

i am getting the message
“Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in…”

how can i fix that and why is that happening? Given that the query is correct shouldn’t it run smoothly?

thanks in advance :slight_smile:

Is your query inserting or selecting ?
You look like you are inserting / updating records from a file into the database and then trying to get information back without a select query.

hm…here I am again…
this time the problem is realy simple… i have a txt file and want to load it on a table.

the query is :

[php]LOAD DATA LOCAL INFILE ‘C:\Program Files\File1\File2\File3\problem.txt’
REPLACE INTO TABLE table1
FIELDS TERMINATED BY ‘,’";

this works fine on MySQL but when i am trying to use a php script for it:

<?php $mysqli=mysql_connect("localhost","root","username","database"); if (mysqli_connect_errno()){ printf("connection failed"); } else { mysql_select_db("database") or die(mysql_error()); $sql = "LOAD DATA LOCAL INFILE 'C:\\Program Files\\File1\\File2\\File3\\problem.txt' REPLACE INTO TABLE `table1` FIELDS TERMINATED BY ','"; } ?>[/php]

the data is not loaded…

i have a similar problem when i am trying to delete the data from the table…what am i doing wrong?

[php]mysql_select_db(“database”) or die(mysql_error());[/php]

[php]mysqli_select_db(“database”, $mysqli) [/php]

ok…i tried to replace the line as you suggested and i get this :

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:…

btw, in the original php file i have a second query which runs fine…i just can’t upload the data but it seems that the connection is fine (since the second query runs).

[php]mysqli_select_db( $mysqli , “database”) [/php]

ok…now i get this…

Parse error: syntax error, unexpected ‘$sql’ (T_VARIABLE) in C:…

First put your code in code tags so i know you can do it then keep doing it in each post

Did you add a semicolon to the end of the line ? [size=12pt];[/size]

[php]<?php
$mysqli=mysql_connect(“localhost”,"username,“password”,“database”);
if (mysqli_connect_errno()){
printf(“connection failed!!”);
} else
{

mysqli_select_db( $mysqli , “database”) ;

$sql = “LOAD DATA LOCAL INFILE 'C:… ’
REPLACE INTO TABLE table1
FIELDS TERMINATED BY ‘,’”;
}
?>[/php]

Warning: mysqli_select_db() expects parameter 1 to be mysqli, resource given in C:\Program Files…

mysql_connect

every thing has to be mysqli not mysql

ok…i don’t see any error messages but it is still not working…

[php]

<?php $mysqli=mysqli_connect("localhost","username","password","database"); if (mysqli_connect_errno()){ printf("connection failed"); } else { mysqli_select_db($mysqli ,"database") ; $sql = "LOAD DATA LOCAL INFILE 'C:\\....' REPLACE INTO TABLE `table1` FIELDS TERMINATED BY ','"; } ?>

[/php]

[php] $sql = “LOAD DATA LOCAL INFILE 'C:\…'REPLACE INTO TABLE table1FIELDS TERMINATED BY ‘,’” or die($mysqli->error);’[/php]

still…no error but the data is not uploaded… :’(

OK solved it…i was missing the mysql_query($sql)

Sponsor our Newsletter | Privacy Policy | Terms of Service