PDA

View Full Version : MySQL Error with script...


user00265
2-26-04, 02:13 PM
Hello there, I have been using this script for some time now, but since they were moved to the FTP servers I've been having errors with them.

The email I get with the error is:
Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

But since I know the basics on how to query a MySQL server for the data I need, I am asking for assistance.

Here is the script (originally written by HalfaBee):
<?
mysql_connect("mysql03.powweb.com","username","password") or die("Error: ".mysql_error());
mysql_select_db("database") or die("Error: ".mysql_error());

$tables = "OPTIMIZE TABLES `";
$res = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_array($res)) {
$tables .= $row[0].'`, `';
}
$tables = preg_replace('/,$/','', $tables);
$length = strlen($tables)-3;
$tables = substr($tables, 0, $length);

mysql_query($tables.";") or die("Error: ".mysql_error());

mysql_close();
exit();
?>

Any help is appreciated.

-Samuel

user00265
2-26-04, 06:57 PM
*bump*

HalfaBee
2-26-04, 07:17 PM
Echo the sql so you can see where the error is.

user00265
2-26-04, 09:11 PM
They work OK via a browser, just that in cron they say that MySQL error.

http://bbdiscuss.com/trace/optimize0.php
http://bbdiscuss.com/trace/optimize1.php
http://bbdiscuss.com/trace/repair0.php
http://bbdiscuss.com/trace/repair1.php


-Samuel

HalfaBee
2-26-04, 10:14 PM
You will have to see what the errors are when cron runs it.
If you put
MAILTO=me@mysite.com

at the top the output is sent to the email addr.

user00265
2-26-04, 10:43 PM
Oddly enough... it is working now?

user00265
2-28-04, 05:04 AM
Shizzle!

Now that I check my email, I get ALOT of emails from cron (it is set to run hourly) abou the same error, so I edited a line on the script:

mysql_query($tables.";") or die("Error: ".$tables.";");

And I got that the tables are not being inserted into the $tables variable at all!
Email said:
Error: OPTIMIZE TABLE;

Now I am REALLY puzzled as why this works on browser but not on cron...


-Samuel :(

user00265
2-29-04, 02:15 AM
*bump*