mysqli准备了期望参数? [英] mysqli prepared expect parameter?

查看:63
本文介绍了mysqli准备了期望参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编写自己的数据库类.遇到一些问题.

I try to write own database class.I have some problem.

当我运行它时,会出现这些错误.

When I run it , it gives these errors.

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 75

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 76

Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 77

Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 78

在这些行上;

mysqli_stmt_bind_param($sor, 's', $hede);
mysqli_stmt_execute($sor);
mysqli_stmt_bind_result($sor, $bas);
mysqli_stmt_fetch($sor);

我将给出databse类的简短版本.不完全是,我只是写我使用的东西.

I will give short version of databse class.It is not exactly, I write just what I use.

class db{

    public $durum;
    protected $server = 'localhost'; 
    protected $suser = 'root'; 
    protected $spass = 'root';
    public $db = 'members'; 

    public $durum; // mysqli durumu
    public $sor; // mysql_query ile birleştirilen hali
    public $kacsonuc;

    function db(){
        $this->durum = mysqli_connect($this->server,$this->suser,$this->spass);
        $this->dbchoose($this->db)
    }

    function dbchoose($db){
        if(!mysqli_select_db($this->durum,$db)){ 
            $this->errors[] = 'Database cant choose';
            $this->hata=True;
        }

    function see(){
        $id = 'select * from uyeler where id=?';
        $sor = mysqli_prepare($this->durum, $id);
        $hede = '3';
        mysqli_stmt_bind_param($sor, 's', $hede);
        mysqli_stmt_execute($sor);
        mysqli_stmt_bind_result($sor, $bas);
        mysqli_stmt_fetch($sor);
    }

}

出什么问题了?我听不懂.谢谢(对不起我的语法师.)

what is the problem ? I cant understand.Thank you (and sorry for my grammer).

推荐答案

每当您在mysql错误消息中看到给定布尔值"时,都意味着以前的某些mysql函数调用失败,返回布尔值FALSE.您正在尝试在当前的mysql调用中使用该布尔值false,并获取此消息.

Anytime you see "boolean given" in a mysql error message, it means that some previous mysql function call has failed, returning a boolean FALSE value. You're trying to use that boolean false in the current mysql call, and get this message.

您的代码中没有错误处理,这意味着那些FALSE值将在整个代码中传播,并随处散布这些错误.

You have no error handling in your code, which means those FALSE values will propagate throughout your code, spitting out those errors everywhere it goes.

至少在每次执行mysql/mysqli调用的地方,您的代码至少应如下所示:

At minimum, your code should look something like this, everywhere you do a mysql/mysqli call:

function see(){
    $id = 'select * from uyeler where id=?';
    $sor = mysqli_prepare($this->durum, $id);
    if ($sor === FALSE) {
        die(mysqli_error($this->durm));
    }
    etc...
}

如何处理错误取决于您-在这种情况下,它只会中止脚本并告诉您原因.

How you handle the error is up to you - in this case it'll simply abort the script and tell you why.

这篇关于mysqli准备了期望参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆