views:

333

answers:

4

I have a bash-sctipt running 5 php scripts via wget. Every php file is called but, on the last script, I get this warning:

mysql_query(): supplied argument is not a valid MySQL-Link resource in xyz.php, on line ABC

What it is really strange is, if I run the same script via browser, the script runs fine, without any warning.

This is my code near line ABC:

$sqlSTR="INSERT INTO accounts_cstm (id_c, mtk_categoriascompradas_c) VALUES ('". $arr[1] . "', '" . $arr[0] . "')
        ON DUPLICATE KEY UPDATE mtk_categoriascompradas_c= concat(mtk_categoriascompradas_c, '^,^$arr[0]')";  

$ExecuteSQL = mysql_query ($sqlSTR, $DBConn) or
          die ($sqlSTR); //warning on this line - line ABC

My SQL is totally valid (if I run the query that is outputed in the "die" statement it runs perfectly), the DBConn is connected to the database and all other scripts run fine, except this one.

I really don't know what is causing this Warning. Any help will be welcome.

Thanks

A: 

Something definitely looks wrong with your last reference to $arr[0] in the query - I think it needs to be the following:

$sqlSTR="INSERT INTO accounts_cstm (id_c, mtk_categoriascompradas_c) VALUES ('". $arr[1] . "', '" . $arr[0] . "')
ON DUPLICATE KEY UPDATE mtk_categoriascompradas_c= concat(mtk_categoriascompradas_c, '^,^".$arr[0]."')";
BrynJ
+4  A: 

Your problem actually lies with your database connection ($DBConn). Take a look at that code. Stick a var_dump in and try wgetting again.

Oli
+1, yes the error does seem to point to an issue with the connection.
BrynJ
no sure, because I can run the script via browser, with exactly the same URL.
Armadillo
I'm not saying it for my own health. The error *means* the database connection isn't valid. You need to look at that part of the code if you want to find the problem.
Oli
+1  A: 

Always use mysql_error() when you see this error message. Then you`ll know the exact reason, why the query was invalid.

Maciej Łebkowski
A: 

Does the URL you are calling with wget have an ampersand in it? If you do, make sure your shell isn't interpreting it as a send process to background

Eddy
The URL doesn't have any ampersand or any special character.
Armadillo
Okay. I'm not familiar with how debian does php, but my ubuntu boxes have a different php.ini for command-line vs apache. You might have a similar setup with the cli-php having a slightly different setup that is affecting your script.
Eddy