2011-01-18 127 views
2

匹配的参数数我有以下代码:PHP,mysqli_stmt :: bind_param()[mysqli的-stmt.bind-PARAM]:变量数不准备语句

$id = $_GET['id']; 

// get the recod from the database 
if($stmt = $mysqli->prepare("SELECT * FROM date WHERE id=?")) 
{ 
     $stmt->bind_param("isssssssss", $id, $mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email); 
     $stmt->execute(); 

     $stmt->bind_result($id, $mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email); 
     $stmt->fetch(); 

     // show the form 
     renderForm($mtcn, $amount, $currency, $sender_name, $sender_country, $receiver_name, $comment, $support, $email, NULL, $id); 

     $stmt->close(); 
} 
// show an error if the query has an error 
else 
{ 
     echo "Error: could not prepare SQL statement"; 
} 

,其生成以下错误/警告:

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in C:\wamp\www\records.php on line 143 

Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: (HY000/2031): No data supplied for parameters in prepared statement in C:\wamp\www\records.php on line 144 

Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in C:\wamp\www\records.php on line 146 

Warning: mysqli_stmt::fetch() [mysqli-stmt.fetch]: (HY000/2053): Attempt to read a row while there is no result set associated with the statement in C:\wamp\www\records.php on line 147 

而表单不完整的数据从数据库,因为我期待...任何意见/帮助将不胜感激。

回答

3

您误解了语句的使用。

在您的查询语句中,您只需绑定一个参数即id。

$stmt->bind_param("i", $id); 
$id = 5; // fetch the fifth record 
$stmt->execute(); 

然后通过获取结果对象访问查询结果中的值。

退房的mysqli_stmt ::执行为例,php.net

+0

我仍然得到警告:mysqli_stmt :: bind_result()[mysqli的-stmt.bind-结果]:绑定变量数不匹配的数第146行的C:\ wamp \ www \ records.php中已准备好的语句中的字段。但从我的行我看到,变量的数量匹配字段的数量。我错过了什么吗? – Michael 2011-01-18 22:28:08