2013-08-17 43 views
0

我学习用准备好的发言中我的数据库,以从表中选择我的所有数据。但是我得到这个错误PHP编写的语句错误:警告:mysqli_stmt :: bind_param():

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match 
number of parameters in prepared statement in 
/Applications/XAMPP/xamppfiles/htdocs/contenteditable/classes/class.Insert.inc on 
line 13 

也许我没有以正确的方式使用准备好的陈述,我不确定,我已经使用过预先准备好的陈述,所以希望有人能告诉我我哪里会出错或者有没有一个有用的工作示例。

这是我的代码:

的index.php

<div id="maincontent" contenteditable="true"> 
    <?php 
     //get data from database. 
     require("classes/class.Insert.inc"); 
     $insert = new Insert(); 
     $insert->read(); 
    ?> 

    <button id="save">Save</button> 
     <input type="button" id="clear" value="Clear changes" /> 

    </div> 

类/ class.Insert.php

<?php 
include("connect/class.Database.inc"); 

class Insert extends Database { 

    public $firstname; 
    public $content; 

public function read(){ 

    $stmt = $this->mysqli->prepare('SELECT * FROM datadump'); 
    $stmt->bind_param('s', $content); 

    $stmt->execute(); 

    $result = $stmt->get_result(); 
    while ($row = $result->fetch_assoc()) { 
     echo $content;  } 
     }   
    } 
?> 

回答

1

bind_param结合参数您的查询,其具有零个占位符。这导致PHP抱怨。

您可能打算使用bind_result来代替,这是将结果集数据导出到变量的方式。

+0

当我将此更改为'bind_result'时,出现以下错误:致命错误:无法通过/Applications/XAMPP/xamppfiles/htdocs/contenteditable/classes/class.Insert.inc中的引用传递参数1, Jon – 001221

+0

@gutigrewal:您是否阅读过'bind_result'手册?它没有采用“s”参数,因为这没有任何意义(数据库已经知道列的数据类型)。用一个功能的名称代替另一个功能的名称并不会奇迹般地使事情发挥作用,这并不奇怪。 – Jon

+0

'警告:mysqli_stmt :: bind_result():绑定变量的数量与第15行中的/Applications/XAMPP/xamppfiles/htdocs/contenteditable/classes/class.Insert.inc中的预准备语句中的字段数目不匹配当我拿出's'时出现这个错误@jon – 001221

相关问题