Maison >développement back-end >tutoriel php >PHP预处理语句执行过程中不知道什么有关问题,求大神解答,分数不多,下面是代码
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 protected]';<br /> mysqli_stmt_execute($stmt);<br /> <br /> $firstname = 'Mary';<br /> $lastname = 'Moe';<br /> $email = [email protected]';<br /> mysqli_stmt_execute($stmt);<br /> <br /> $firstname = 'Julie';<br /> $lastname = 'Dooley';<br /> $email = [email protected]';<br /> mysqli_stmt_execute($stmt);<br /> <br /> echo '插入成功';<br /> }<br />}<br />