2013-04-14 76 views
-1

我有一份声明一个问题,这里是我的代码:mysqli的致命错误:调用一个成员函数bind_param()一个非对象

function query_array($table, $data) { 
    foreach ($data as $column => $value) { 
     $columns[] = sprintf("`%s` = '%s'", $column, $this->db->real_escape_string($value)); 
    } 
    $column_list = join(',', $columns); 

    // Prepare the statement 
    $stmt = $this->db->prepare("UPDATE `?` SET ?"); 
    $stmt->bind_param('ss', $table, $column_list); 

    // Execute the statement 
    $stmt->execute(); 

    // Save the affected rows 
    $affected = $stmt->affected_rows; 

    // Close the statement 
    $stmt->close(); 

    // ... 
} 

$这个 - >数据库返回一个对象;

$ table ='settings'; (串)

$ column_list中:(串)

`title` = 'Socialsd',`captcha` = '0',`public` = '',`private` = '',`time` = '1',`perpage` = '10',`message` = '140',`mail` = '1',`inter` = '10000',`size` = '1048576',`format` = 'png,jpg,gif',`sizeMsg` = '1048576',`formatMsg` = 'png,jpg,gif,bmp',`censor` = '',`ad1` = '',`ad2` = '' 

我得到的错误是:

Fatal error: Uncaught exception 'ErrorException' with message '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' in C:\xampp\htdocs\new\includes\classes.php:256 Stack trace: #0 C:\xampp\htdocs\new\sources\admin.php(225): updateSettings->query_array('settings', Array) #1 C:\xampp\htdocs\new\index.php(42): PageMain() #2 {main} thrown in C:\xampp\htdocs\new\includes\classes.php on line 256

我想不出是什么原因导致的,因为尝试了以下工作就好:

$query = sprintf("UPDATE `%s` SET %s", $table, $column_list); 
$result = $this->db->query($query); 

任何帮助表示赞赏。

更新1:我可以知道为什么这个会被低估吗?这将是很高兴知道。

更新2:所以我已经删除了最后绑定($ column_list中),并把在声明$ column_list中的整个输出,所以基本上我只绑定表名,现在我得到另一个错误:

Can't find file: '.\diary\@003f.frm' (errno: 22)

现在我真的很困惑。

+0

[mysqli :: prepare SQL error](http://stackoverflow.com/q/11559186/1409082)可能出现重复。 – Jocelyn

+0

@Jocelyn感谢您的评论,即使我手动将表名设置为'settings',错误仍然存​​在,完全一样。 –

回答

相关问题