<?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的更多相关文章

  1. jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...

    写了一个html,用到了jQuery,发现没有按照预期的结果显示,最后定位到是$.get()函数没有运行 调试过程为: 在页面右击查看元素,到网络那一栏,找到类型为json的那个包点击,然后查看响应, ...

  2. 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 ...

  3. 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. ...

  4. SSM Mybatis将新增数据写入数据库时出现的500状态码:Error updating database.的可能

    关于maven下ssm整合的项目推荐这篇博客:https://www.cnblogs.com/yiye/p/5969157.html 今日在ssm下的将新增数据写回数据库时遇到不少的问题,现作记录 如 ...

  5. 在用UEditor往后台传数据写入数据库时,出现错误:从客户端(NewsContent="<p><img src="http://...")中检测到有潜在危险的 Request.。。。

    解决办法: 把传数据的方式换了一下,加上 [ValidateInput(false)]就不报错了. 建议看看这个:http://www.360doc.com/content/10/0521/15/46 ...

  6. Python操作pymysql写入数据库时的错误

    错误一 InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE6\\xAD\\xA3 ...

  7. python将excel数据写入数据库,或从库中读取出来

    首先介绍一下SQL数据库的一些基本操作: 1创建 2删除 3写入 4更新(修改) 5条件选择 有了以上基本操作,就可以建立并存储一个简单的数据库了. 放出python调用的代码: 此处是调用dos 操 ...

  8. RFID射频卡超市购物结算系统问题记录--写入卡片时,后台php无法操作数据库

    后台管理人员要给每件商品贴上RF卡作为唯一标识,所以要先给对应的RFID卡中写入响应的信息,我这里为了便于模拟演示只写入商品编号,价格,名称这几个字段,然后要把已经写入的商品上传后台,由后台写入数据库 ...

  9. redis数据库写入数据时提示redis.exceptions.ResponseError错误

    今天运行Django项目在redis数据库写入数据时提示如下错误: ERROR log 228 Internal Server Error: /image_code/cf9ccd75-d274-45c ...

随机推荐

  1. 设计模式之中介者模式(php实现)

    github地址:https://github.com/ZQCard/design_pattern /** * 中介者模式(Mediator Pattern)是用来降低多个对象和类之间的通信复杂性. ...

  2. Uncaught SyntaxError: Invalid Unicode escape sequence异常处理

    今天碰到一个问题,页面报错:Uncaught SyntaxError: Invalid Unicode escape sequence ,{index:'operate',name:'operate' ...

  3. [Angular] Dynamic component rendering by using *ngComponentOutlet

    Let's say you want to rending some component based on condition, for example a Tabs component. Insid ...

  4. HUNAN Interesting Integers(爆力枚举)

    Undoubtedly you know of the Fibonacci numbers. Starting with F1 = 1 and F2 = 1, every next number is ...

  5. IO流(二)I/O

    一.IO流概述 1.定义:Java的IO流是实现输入输出的基础,它可以方便地实现数据的输入/输出操作. 2.流的分类: (1)按流向来分:输入流和输出流 (2)按操作的数据来分:字节流和字符流 (3) ...

  6. C# Redis Server分布式缓存编程(一)

    这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...

  7. vsftpd 配置:chroot_local_user与chroot_list_enable userlist_enable userlist_deny详解

    默认情况下,如果设置了 userlist_enable=YES,当 userlist_deny 选项设置为 YES 的时候,userlist_file=/etc/vsftpd.userlist 中列出 ...

  8. SecureCRT如何调整好看的黄色

    1.常规 →默认会话→编辑默认编辑→白黑 字体为console 2.全局选项 ANSI颜色有一个 把黄色 拖过去即可

  9. linux ln 命令使用参数详解(ln -s 软链接)(转)

    这是linux中一个非常重要命令,请大家一定要熟悉.它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln -s 源文件 目标文件. 当 我们需要在不同的 ...

  10. NoSQL之Redis学习小结

    大数据时代要求: 三V:Volume海量.Velocity实时.Variety多样: 三高:高并发.高可扩.高性能 高并发操作不建议使用关联查询,而使用冗余数据,分布式系统支持不了太多的并发. 横向 ...