Mysqli 抛出“警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,给

Mysqli throws quot;Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean givenquot;(Mysqli 抛出“警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,给出布尔值;)
本文介绍了Mysqli 抛出“警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,给出布尔值";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我知道此代码在我拥有的另一个网站上有效,但今天无法正常运行.我收到三个警告:

I know that this code works on another site I've got but it's not playing ball today. I get three warnings:

警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,布尔值在/homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php 第 33 行

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php on line 33

警告:mysqli_execute() 期望参数 1 为 mysqli_stmt,布尔值在/homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php 第 34 行

Warning: mysqli_execute() expects parameter 1 to be mysqli_stmt, boolean given in /homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php on line 34

警告:mysqli_stmt_affected_rows() 期望参数 1 为 mysqli_stmt,布尔值在/homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php 第 35 行

Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php on line 35

有人能帮我解决这个问题吗?

Can someone help me figure this out?

如果有帮助,我必须使用 htaccess 升级到 PHP5.

I am having to use htaccess to upgrade to PHP5 if this helps.

$connection = mysqli_connect($hostname, $username, $password, $dbname);

if (!$connection) {
    die('Connect Error: ' . mysqli_connect_error());
}

$query = "INSERT INTO entries (name, dob, school, postcode, date) VALUES (?,?,?,?,?)";
$stmt1 = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt1, 'sssss',$name,$dob,$school,$postcode,$date);
mysqli_execute($stmt1);
if(mysqli_stmt_affected_rows($stmt1) != 1)
    die("issues");
mysqli_stmt_close($stmt1);
return "new";

编辑

经过一些调查发现,prepare 语句与 mysql4 不起作用.我创建了一个新的 mysql5 数据库,但是当我尝试连接时出现此错误:

After some investigation it transpires that the prepare statement doesn't play ball with mysql4. I have created a new mysql5 database but I now get this error when I try to connect:

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'localhost:/tmp/mysql5.sock' (1)

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'localhost:/tmp/mysql5.sock' (1)

有人知道为什么会这样吗?

Does anyone have any idea as to why this is happening?

推荐答案

添加更多错误处理.
当连接失败时,mysqli_connect_error() 可以告诉你更多细节.
当准备语句失败时,mysqli_error() 有关于错误的更多信息.
当语句执行失败时,询问mysqli_stmt_error().等等等等...
任何时候 mysqli 模块的函数/方法返回 false 以指示错误,a) 处理该错误和 b) 决定继续是否有意义.例如.连接失败时继续进行数据库操作是没有意义的.但是当只有一次插入失败时继续插入数据可能是有意义的(可能有意义,可能没有).

Add more error handling.
When the connection fails, mysqli_connect_error() can tell you more details.
When preparing the statement fails mysqli_error() has more infos about the error.
When executing the statement fails, ask mysqli_stmt_error(). And so on and on...
Any time a function/method of the mysqli module returns false to indicate an error, a) handle that error and b) decide whether it makes sense or not to continue. E.g. it doesn't make sense to continue with database operations when the connection failed. But it may make sense to continue inserting data when just one insertion failed (may make sense, may not).

为了测试,你可以使用这样的东西:

For testing you can use something like this:

$connection = mysqli_connect(...);
if ( !$connection ) {
  die( 'connect error: '.mysqli_connect_error() );
}

$query = "INSERT INTO entries (name, dob, school, postcode, date) VALUES (?,?,?,?,?)";
$stmt1 = mysqli_prepare($connection, $query);
if ( !$stmt1 ) {
  die('mysqli error: '.mysqli_error($connection);
}
mysqli_stmt_bind_param($stmt1, 'sssss',$name,$dob,$school,$postcode,$date);
if ( !mysqli_execute($stmt1) ) {
  die( 'stmt error: '.mysqli_stmt_error($stmt1) );
}
...

对于真正的生产环境,这种方法很健谈,而且很容易死掉;-)

For a real production environment this approach is to talkative and dies to easily ;-)

这篇关于Mysqli 抛出“警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,给出布尔值";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

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 的问题)