Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[Solved] SQL query works fine in command line, not in safe_query()
This is just doing my head in! I might have been looking too long at it. This is the error which I’m getting after calling safe_query():
Warning: 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
'ALTER TABLE `textpattern` MODIFY `custom_3` VARCHAR(255) NOT NULL DEFAULT ''' at line 1
UPDATE `textpattern` SET `custom_3` = ''; ALTER TABLE `textpattern` MODIFY `custom_3` VARCHAR(255) NOT NULL DEFAULT '';
/var/www/glz_custom_fields/lib/db.php:37 glz_reset_custom_field() in /var/www/textpattern-4.2.0/textpattern/lib/txplib_db.php on line 85
Same query, executed on the command line:
mysql> UPDATE `textpattern` SET `custom_3` = ''; ALTER TABLE `textpattern` MODIFY `custom_3` VARCHAR(255) NOT NULL DEFAULT '';
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
This is the bit of code which throws the above error:
else if ( $table == PFX."textpattern" ) {
$query = "UPDATE `".PFX."textpattern` SET `{$name}` = ''; ";
$query .= "ALTER TABLE `".PFX."textpattern` MODIFY `{$custom_field}` VARCHAR(255) NOT NULL DEFAULT '';";
}
safe_query($query);
What am I missing?
Last edited by gerhard (2009-09-26 21:47:56)
Offline
Re: [Solved] SQL query works fine in command line, not in safe_query()
It’s not pretty, but it seems to be working. Still can’t understand why…
else if ( $table == PFX."textpattern" ) {
safe_query("UPDATE `".PFX."textpattern` SET `{$name}` = ''");
safe_query("ALTER TABLE `".PFX."textpattern` MODIFY `{$custom_field}` VARCHAR(255) NOT NULL DEFAULT ''");
}
Offline
Offline
Offline
Offline
Re: [Solved] SQL query works fine in command line, not in safe_query()
gerhard wrote:
So what happens when you have 10 queries queued for execution, do you run them one by one? That doesn’t sound right…
It’s handled by PHP. It’s not as bad as it seems. Note that mysql_query
always returns something (single value). If you want to save memory there are alternative ways.
Thanks for your help!
Np.
Last edited by Gocom (2009-09-26 22:30:53)
Offline
Re: [Solved] SQL query works fine in command line, not in safe_query()
If multiple SQL queries were supported by default (it is possible, see the comments in the PHP manual) and there was an SQL injection vulnerability in your code, the possibilities for exploiting it would be far greater.
Offline