Heim >Backend-Entwicklung >PHP-Tutorial >急请高手指导关于Mysqli的prepare出错有关问题
急!!!请高手指导关于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);