php新主机与双引号错误

时间:2014-03-03 09:45:14

标签: php hosting quote

在我的所有PHP脚本运行正常之前,我刚刚更改了我的主机

但现在我得到很多这样的mysql错误:

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 column = \'value\' 

似乎某些脚本中有双引号

有一种方法可以在不更新所有PHP脚本的情况下解决问题吗?

编辑:PHP代码示例

function test( $table,$column, $where ){

if( get_magic_quotes_gpc() ) { $where = strip_tags( trim( $where ) ); }
else{  $where = strip_tags( mysql_real_escape_string( trim( $where ) ) ); }

$where = "AND id = '" . $where . "' ";

$query = "SELECT " . $column . " FROM " . $table . " WHERE 1 " . $where . " LIMIT 1";
//...

2 个答案:

答案 0 :(得分:1)

如果在外部定义,则必须传递$table变量或将其声明为全局变量。

function test( $column, $where ){
global $table;    

if( get_magic_quotes_gpc() ) { $where = strip_tags( trim( $where ) ); }
else{  $where = strip_tags( mysql_real_escape_string( trim( $where ) ) ); }

$where = "AND id = '" . $where . "' ";

$query = "SELECT " . $column . " FROM " . $table . " WHERE 1 " . $where . " LIMIT 1";

答案 1 :(得分:0)

如果您的函数看起来像这样会发生什么?

function test( $table,$column, $where ){
    $where=stripslashes($where);
    $where = strip_tags(mysql_real_escape_string(trim( $where )));
    $where = "AND id = '" . $where . "' ";
    $query = "SELECT " . $column . " FROM " . $table . " WHERE 1 " . $where . " LIMIT 1";
}