Reputation: 6943
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
Upvotes: 0
Views: 618
Reputation: 1862
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
Upvotes: 0
Reputation: 3942
Always use mysql_error()
when you see this error message. Then you`ll know the exact reason, why the query was invalid.
Upvotes: 1
Reputation: 239908
Your problem actually lies with your database connection ($DBConn
). Take a look at that code. Stick a var_dump in and try wgetting again.
Upvotes: 4
Reputation: 8382
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]."')";
Upvotes: 0