您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

急请高手指导关于Mysqli的prepare出错有关问题

2025/1/10 8:43:14发布18次查看
急!!!请高手指导关于mysqli的prepare出错问题
很久没写程序了,由于php5.0升级的mysqli类操作数据库有很多优点,本人想尝试用mysqli的方法操作数据库,经过从网上查资料、看手册,浏览、删除都能正常实现,唯独插入功能总是提示错误:fatal error: call to a member function prepare() on null in d:\xampps\htdocs\txl\addbook.php on line 20  。
快愁死我了,难道这个问题解决不了我要放弃mysqli吗?请高手指点我的代码错在哪里?还是服务器的问题?(服务器我用的是xampps1.9.7集成环境)
if($_post['contacts'] == true)
{
    $stmt = $mysqli->prepare(insert into contactsuser(bookuname, bookdep, bookduty,bookphone,booktel,bookemail,bookgid) values (?, ?, ?, ?, ?, ?, ?));
    $stmt->bind_param('sssd', $bookuname, $bookdep, $bookduty, $bookphone, $booktel, $bookemail, $bookgid);
$bookuname = $_post['bookuname'];
    $bookdep = $_post['bookdep'];
    $bookduty = $_post['bookduty'];
    $bookphone = $_post['bookphone'];
    $booktel = $_post['booktel'];
    $bookemail = $_post['bookemail'];
    $bookgid = $_post['bookgid'];
/* execute prepared statement */
    $stmt->execute();
    printf(%d row inserted.\n, $stmt->affected_rows);
    /* close statement and connection */
    $stmt->close();
    exit;
}
------解决思路----------------------
$mysqli 不是 mysqli 对象
------解决思路----------------------
试试面向过程风格的方法:
$stmt = mysqli_prepare($link, insert into contactsuser(bookuname, bookdep, bookduty,bookphone,booktel,bookemail,bookgid) values (?, ?, ?, ?, ?, ?, ?))
------解决思路----------------------
mysqli_stmt_bind_param($stmt,'ssssssd', $bookuname, $bookdep, $bookduty, $bookphone, $booktel, $bookemail, $bookgid);
http://php.net/manual/zh/mysqli-stmt.bind-param.php
the number of variables and length of string types must match the parameters in the statement.
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product