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 ...
随机推荐
- Ext JS 5 gpl版本 官方原版的下载方法
先进入官网: 然后在导航的Products中选择Sencha Ext JS,会看到以下页面: 这时候不要单击Download按钮,而是要单击导航中的DETAILS,页面切换后,就可在底部看到GPL版本 ...
- 关于hibernate中映射中有many to one等外键关联时的问题
hibernate中的对象的3种状态的理解及导致报错object references an unsaved transient instance - save the transient insta ...
- Android NDK生成共享库和静态库
Date: 2014-03-14 Title: Compile Android Native Binary And Library Published: true Type: post Tags: A ...
- JAVA Eclipse如何开发Android的多页面程序
Fragment可以认为是Activity的一个界面的组成部分,Fragment必须依存于Activity. 在layout文件夹中新建一个xml文件,布局方式采用RelativeLayout,注 ...
- SQL 关键字 'USER' 附近有语法错误怎么办
如下图所示,我想要访问我的Database1.mdf的user这张表,提示如下错误 user在SQL Server中是系统保留字,将user修改为[user]就可以了.但是直接在VS中是无法修改的 ...
- Vue-router(vue2.0)用法示例
一.新建3个组件 1./src/components/post.vue <template> <div> hello world! this is POST! </div ...
- TCO'10 Wildcard Round 1000pt
题目大意: 给定一个N*M的棋盘,棋子可以攻击其左右距离不超过K的棋子.问有多少种放法使得棋盘上的棋子不能互相攻击. N,M,K都在1到1000000000的范围内,结果对100003取模. 官方题解 ...
- Vue mixins extend
const mixins = { created () { console.log('mixins created') } } const mixins2 = { created () { conso ...
- 微信java开发之实现微信主动推送消息
1.拉取access_token2.拉取用户信息3.主动推送消息4.接口貌似要申请权限5.依赖httpclient4.2.3 和jackson 2.2.1 public class WeixinAPI ...
- 51单片机 | 定时/计数器原理及结构(T0和T1)
———————————————————————————————————————————— 定时/计数器结构(T0和T1) 16位寄存器T0.T1分别由TH0.TL0和TH1.TL1四个8位计数器组成 ...