Jump to content

Archived

This topic is now archived and is closed to further replies.

kkroo

SQL errors

Recommended Posts

I created an automatic backup script, and occasionally, i will get some errors like:

FAILED IN get_table_def (show keys) on line372 in/home/***/public_html/forum/includes/auto_backup.php
SHOW KEYS FROM

Failed in get_table_def (show fields) on line337 in/home/***/public_html/gcc/forum/includes/auto_backup.php
SHOW FIELDS FROM

Failed in get_table_content (select *) on line535 in/home/**/public_html/gcc/forum/includes/auto_backup.php
SELECT * FROM

i added a filter to see if the var is empty, and it passes, so i think it may be a syntax error

this is the way the query looks like: SELECT * FROM table_name
SHOW KEYS FROM table_name

does it maybe have to be like this: SELECT * FROM `table_name`
SHOW KEYS FROM `table_name`
here is the script:

[a href=\"http://phpbb-login.sourceforge.net/forum/dload.php?action=file&file_id=13\" target=\"_blank\"]http://phpbb-login.sourceforge.net/forum/d...file&file_id=13[/a]

Any help will be highly appreciated

Share this post


Link to post
Share on other sites
the script is pretty complex (almost 800 lines) and the specific error is never reported. I looked at the code and didn't find anything until I got to line 535
[code]
        email_message_die("Failed in get_table_content (select *)", "", __LINE__, __FILE__, "SELECT * FROM $table;");
[/code]

it's dumping your query as the error message (or so it would appear). The query is "SELECT * FROM" -- which appears to be missing the $table variable. 535 is inside a function called get_table_content_mysql() -- the function expects to receive $table when called -- but I can't find where the function is called!

Share this post


Link to post
Share on other sites
if $table is somehow a keyword in mysql, then you'll get the error. if you surround $table with `` then you are telling mysql to not treat that part as a keyword, which should solve the problem.

Share this post


Link to post
Share on other sites
so just add `` around all occurances of $table in queries? BTW, is it manditory to have the ; at the end of a query?

Share this post


Link to post
Share on other sites
oops, my bad --- not supposed to use that at all.

[!--quoteo(post=376438:date=May 23 2006, 02:02 PM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 23 2006, 02:02 PM) [snapback]376438[/snapback][/div][div class=\'quotemain\'][!--quotec--]
so just add `` around all occurances of $table in queries? BTW, is it manditory to have the ; at the end of a query?
[/quote]

Share this post


Link to post
Share on other sites
[!--quoteo(post=376438:date=May 23 2006, 12:02 PM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 23 2006, 12:02 PM) [snapback]376438[/snapback][/div][div class=\'quotemain\'][!--quotec--]
so just add `` around all occurances of $table in queries? BTW, is it manditory to have the ; at the end of a query?
[/quote]
Theoretically, ";" is needed to indicate the end of a query, but in php, it's not mandatory.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.