实例
<?php //连接参数 $db_host = '127.0.0.1'; $db_user = 'root'; $db_pass = 'root'; $db_name = 'test'; $db_char = 'utf8'; //创建连接 $db = @new mysqli($db_host,$db_user,$db_pass,$db_name); //检测连接 if($db->connect_errno){ exit($db->connect_error.$db->connect_errno); } //设置默认字符集 $db->set_charset($db_char); //sql语句 $sql_ins = "INSERT IGNORE user SET USER_NAME = ?,USER_AGE = ?,USER_PRO = ?"; $sql_del = "DELETE from user WHERE USER_ID = ?"; $sql_upd = "UPDATE user SET USER_PRO = ? WHERE USER_NAME = ? "; //创建stmt $stmt = $db->stmt_init(); //检测stmt //if($stmt->prepare($sql_ins)){ // $stmt->bind_param('sis',$name,$age,$pro); // $name = '瓦莉拉'; // $age = 130; // $pro = '盗贼'; // $stmt->execute(); //}else { // echo $stmt->errno.$stmt->error; //} //if($stmt->prepare($sql_del)){ // $stmt->bind_param('i',$id); // $id = 12; // $stmt->execute(); //}else { // echo $stmt->errno.$stmt->error; //} if($stmt->prepare($sql_upd)){ $stmt->bind_param('ss',$pro,$name); $name = '瓦莉拉'; $pro = '潜行者'; $stmt->execute(); }else { echo $stmt->errno.$stmt->error; }
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php //创建pdo对象 $pdo = @new PDO('mysql:host=127.0.0.1;dbname=test','root','root'); $stmt = $pdo->prepare("DELETE FROM user WHERE user_id=:id"); $stmt->execute(['id'=>14]);
运行实例 »
点击 "运行实例" 按钮查看在线实例