Home > Backend Development > PHP Tutorial > PHP预处理语句执行过程中不知道什么有关问题,求大神解答,分数不多,下面是代码

PHP预处理语句执行过程中不知道什么有关问题,求大神解答,分数不多,下面是代码

WBOY
Release: 2016-06-13 12:25:28
Original
917 people have browsed it

PHP预处理语句执行过程中不知道什么问题,求大神解答,分数不多,下面是代码

<br />$servername = 'servername'; //服务器名称<br />$username = 'username'; //数据库用户名<br />$password = 'password'; //登录密码<br />$dbname = 'mydb';<br /><br />//创建连接<br />$conn = new mysqli($servername, $username, $password, $dbname);<br /><br />//检测连接(PHP 5.2.9和5.3.0版本适用)<br />/* if($conn->connect_error){<br />	die('连接失败:' . $conn->connect_error);<br />} */<br /><br />//检测连接(兼容更早版本)<br />if(mysqli_connect_error()){<br />	die('连接失败:' . mysqli_connect_error());<br />}<br />else{<br />	$sql = "INSERT INTO myguests VALUES(?, ?, ?)";<br />	<br />	//为mysqli_stmt_prepare()初始化statement对象<br />	$stmt = mysqli_stmt_init($conn); <br />	echo $stmt; //不知道为什么$stmt是空的,没有数据<br />	<br />	//预处理语句<br />	if(mysqli_stmt_prepare($stmt, $sql)){<br />		//绑定参数<br />		mysqli_stmt_bind_param($stmt, 'sss', $firstname, $lastname, $email);<br />		<br />		//设置参数并执行<br />		$firstname = 'Sam';<br />		$lastname = 'Poly';<br />		$email = [email&#160;protected]';<br />		mysqli_stmt_execute($stmt);<br />		<br />		$firstname = 'Mary';<br />		$lastname = 'Moe';<br />		$email = [email&#160;protected]';<br />		mysqli_stmt_execute($stmt);<br />		<br />		$firstname = 'Julie';<br />		$lastname = 'Dooley';<br />		$email = [email&#160;protected]';<br />		mysqli_stmt_execute($stmt);<br />		<br />		echo '插入成功';<br />	}<br />}<br />
Copy after login

好像mysqli_stmt_init($conn)执行后没反应,我echo了一下,没东西输出,所以后面的mysqli_stmt_prepare($stmt, $sql)也执行不下去了,实在不清楚为什么没有执行,也没有报错
------解决思路----------------------
你用混了!
$conn = mysqli_connect(....)
mysqli_stmt_init($conn)
这是一对

$conn = new mysqli(.....)
$conn ->stmt_init()
这才是一对

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template