php 写入数据库时Call to a member function bind_param() on a non-object
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt = $conn->prepare("INSERT INTO MyGuests VALUES(?, ?, ?)");
$stmt->bind_param("sss", $firstname, $lastname, $email);
// 设置参数并执行
$firstname = "John";
$lastname = "Doe";
$email = "john@example.com";
$stmt->execute();
$firstname = "Mary";
$lastname = "Moe";
$email = "mary@example.com";
$stmt->execute();
$firstname = "Julie";
$lastname = "Dooley";
$email = "julie@example.com";
$stmt->execute();
echo "New records created successfully";
$stmt->close();
$conn->close();
?>
运行时报错:
Call to a member function bind_param() on a non-object 原因:
bind_param 的第二个参数是起引用传递的
直接写成字符串,这是在 php 5.3 及以后是不允许的
解决方法:
将 $stmt = $conn->prepare("INSERT INTO myguests VALUES(?,?,?)");
改成$stmt = $conn->prepare("INSERT INTO myguests(firstname, lastname, email) VALUES(?,?,?)");
php 写入数据库时Call to a member function bind_param() on a non-object的更多相关文章
- jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...
写了一个html,用到了jQuery,发现没有按照预期的结果显示,最后定位到是$.get()函数没有运行 调试过程为: 在页面右击查看元素,到网络那一栏,找到类型为json的那个包点击,然后查看响应, ...
- Fatal error: Uncaught Error: Call to a member function bind_param() on boolean
1.2019年10月22日 PHP写mysqli 预编译查询的时候报错. Fatal error: Uncaught Error: Call to a member function bind_par ...
- Fatal error: Call to a member function bind_param() on a non-object in
今天在练习 mysql是出现错误: Fatal error: Call to a member function bind_param() on a non-object in 解决步骤: 1. ...
- SSM Mybatis将新增数据写入数据库时出现的500状态码:Error updating database.的可能
关于maven下ssm整合的项目推荐这篇博客:https://www.cnblogs.com/yiye/p/5969157.html 今日在ssm下的将新增数据写回数据库时遇到不少的问题,现作记录 如 ...
- 在用UEditor往后台传数据写入数据库时,出现错误:从客户端(NewsContent="<p><img src="http://...")中检测到有潜在危险的 Request.。。。
解决办法: 把传数据的方式换了一下,加上 [ValidateInput(false)]就不报错了. 建议看看这个:http://www.360doc.com/content/10/0521/15/46 ...
- Python操作pymysql写入数据库时的错误
错误一 InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE6\\xAD\\xA3 ...
- python将excel数据写入数据库,或从库中读取出来
首先介绍一下SQL数据库的一些基本操作: 1创建 2删除 3写入 4更新(修改) 5条件选择 有了以上基本操作,就可以建立并存储一个简单的数据库了. 放出python调用的代码: 此处是调用dos 操 ...
- RFID射频卡超市购物结算系统问题记录--写入卡片时,后台php无法操作数据库
后台管理人员要给每件商品贴上RF卡作为唯一标识,所以要先给对应的RFID卡中写入响应的信息,我这里为了便于模拟演示只写入商品编号,价格,名称这几个字段,然后要把已经写入的商品上传后台,由后台写入数据库 ...
- redis数据库写入数据时提示redis.exceptions.ResponseError错误
今天运行Django项目在redis数据库写入数据时提示如下错误: ERROR log 228 Internal Server Error: /image_code/cf9ccd75-d274-45c ...
随机推荐
- Lock flag DX
https://msdn.microsoft.com/en-us/library/windows/desktop/bb322846(v=vs.85).aspx discard nooverwrite ...
- 机器学习第1课:引言(Introduction)
1.前言 Machine Learning(机器学习)是研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能. 它是人工智能的核心,是使计算机具有 ...
- 2017.7.31 ELK+logback+redis的使用
参考来自:spring mvc+ELK从头开始搭建日志平台 0 前提 ELK安装成功 redis安装成功 使用logback的项目运行成功 1 配置文件 1.1 pom.xml 为了使用logback ...
- bootstrap之PressKeyCode&&LongPressKeyCode
PressKeyCode package io.appium.android.bootstrap.handler; import com.android.uiautomator.core.UiDevi ...
- 【Datastage】Datastage在win10上安装报错:This Application requires one of the following versions of the .NET Framework:v1.1.4322 Do you want to install this .NET Framework version now?
Datastage在win10上安装报错如下: 这个错误的意思是:.netFramWork的版本不符合要求,于是,我在网上下载了一个版本一致的 下载地址为:http://pan.baidu.com/s ...
- Java种八种常用排序算法
1 直接插入排序 经常碰到这样一类排序问题:把新的数据插入到已经排好的数据列中. 将第一个数和第二个数排序,然后构成一个有序序列 将第三个数插入进去,构成一个新的有序序列. 对第四个数.第五个数……直 ...
- NSMutableAttributedString 的使用方法,设置格式
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:title]; NS ...
- discuz密码生成
Discuz的密码加密算法其实就是两次MD5加密,首先用明文进行一次加密,之后随机生成一个salt,再把第一次的密文后面添加salt作为明文再进行一次MD5加密.salt保存在uc_members表里 ...
- Android下ListView的分页(9.6)
1 http://www.cnblogs.com/noTice520/archive/2012/02/10/2345057.html 2 http://www.92coding.com/blog/in ...
- E - Hangover(1.4.1)
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...