Mysqli Prepare 语句 - 返回 False,但为什么呢?

Mysqli Prepare Statement - Returning False, but Why?(Mysqli Prepare 语句 - 返回 False,但为什么呢?)
本文介绍了Mysqli Prepare 语句 - 返回 False,但为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个函数,它根据要插入到该列中的列名和值的关联数组以及一个表名(一个简单的字符串)生成一个准备好的 INSERT 语句:

I have a function that generates a prepared INSERT statement based on an associative array of column names and values to be inserted into that column and a table name (a simple string):

function insert ($param, $table) {
        $sqlString = "INSERT INTO $table (".implode(', ',array_keys($param)).') VALUES ('.str_repeat('?, ', (count($param) - 1)).'?)';
        if ($statement = $this->conn->prepare($sqlString)):
            $parameters = array_merge(array($this->bindParams($param), $param));
            call_user_func_array(array($statement, 'bind_param', $parameters));
            if (!$statement->execute()):
                die('Error! '.$statement->error());
            endif;
            $statement->close();
            return true;
        else:
            die("Could Not Run Statement");
        endif;
    }

我的问题是 $this->conn->prepare(它是一个类的一部分,conn 是一个新的 mysqli 对象,它没有问题)返回 false,但没有给我一个原因!

My problem is that $this->conn->prepare (it's part of a class, conn is a NEW mysqli object, which works with no issues) returns false, but does not give me a reason why!

这是为准备语句构建的示例 $sqlString:

Here is a sample $sqlString that gets built for the prepare statement:

INSERT INTO students (PhoneNumber, FirstName, MiddleInit, LastName, Email, Password, SignupType, Active, SignupDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)

有人能看出这个参数化语句有什么问题吗?准备函数返回 false 的任何原因?

Can anyone see a problem with this parameterized statement? Any reason the prepare function would return false?

推荐答案

我正在将解决方案复制到此答案中,以便可以对此进行投票,否则该问题将永远出现在未回答的问题"中.我将这个答案标记为 CW,所以我不会得到任何分数.

I'm copying the solution into this answer so this can be given an upvote, otherwise the question will appear in the "unanswered questions" forever. I'm marking this answer CW so I won't get any points.

@Andrew E. 说:

@Andrew E. says:

我刚打开mysqli_report(MYSQLI_REPORT_ALL) 到更好地了解什么是继续 - 结果是我的一个字段名称不正确 - 你会认为 prepare() 会抛出一个异常,但它默默地失败了.

I just turned on mysqli_report(MYSQLI_REPORT_ALL) to get a better understanding of what was going on - turns out that one of my field names was incorrect - you'd think that prepare() would throw an exception, but it fails silently.

这篇关于Mysqli Prepare 语句 - 返回 False,但为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)