实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/24 0024 * Time: 下午 1:08 */ header("content-type:text/html;charset=utf-8"); define("DB_HOST","127.0.0.1"); define("DB_USER","root"); define("DB_PASS","root"); define("DB_NAME","testguest"); define("DB_CHAR","utf8");
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/24 0024 * Time: 下午 1:11 */ header("content-type:text/html;charset=utf-8"); require_once "mysql_config.php"; $conn = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME) or die("数据库连接失败"); $conn->set_charset(DB_CHAR);
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php / * Insert * @param $conn * @param $sql * @param string $username * @param string $password * @param string $type */ function mysqli_stmtInsert($conn,$sql,$username="admin",$password="123456",$type="INSERT"){ $stmt = mysqli_prepare($conn,$sql); mysqli_stmt_bind_param($stmt,"ss",$username,$password); $username = "admin_".time(); $password = sha1("123456"); mysqli_stmt_execute($stmt); echo "执行插入id是:"+mysqli_stmt_insert_id($stmt); mysqli_stmt_close($stmt); mysqli_close($conn); } /医院 * Update * @param $conn * @param $sql * @param string $uuiqid * @param string $question * @param $id * @param string $type */ function mysqli_stmtUpdate($conn,$sql,$uuiqid="admin",$question="123456",$id,$type="UPDATE"){ $stmt = mysqli_prepare($conn,$sql); mysqli_stmt_bind_param($stmt,"ssi",$uuiqid,$question,$id); $uuiqid = sha1(uniqid(rand(),TRUE)); $question = uniqid(rand(),TRUE); mysqli_stmt_execute($stmt); echo "更新受影响的行数:"+mysqli_stmt_affected_rows($stmt); mysqli_stmt_close($stmt); mysqli_close($conn); } /医院 * Delete * @param $conn * @param $sql * @param $id * @param string $type */ function mysqli_stmtDelete($conn,$sql,$id,$type="DELETE"){ $stmt = mysqli_prepare($conn,$sql); mysqli_stmt_bind_param($stmt,"i",$id); mysqli_stmt_execute($stmt); echo "删除受影响的行数:"+mysqli_stmt_affected_rows($stmt); mysqli_stmt_close($stmt); mysqli_close($conn); } /医院 * Select * @param $conn * @param $sql * @param $id * @param string $type */ function mysqli_stmtSelect($conn,$sql,$id,$type="SELECT"){ $stmt = mysqli_prepare($conn,$sql); mysqli_stmt_bind_param($stmt,"i",$id); mysqli_stmt_execute($stmt); // mysqli_stmt_store_result($stmt);//绑定结果集 单语句执行时候貌似没啥影响不知道多语句啥情况,待测试 mysqli_stmt_bind_result($stmt,$username,$password); while (mysqli_stmt_fetch($stmt)){ echo "{$username}] => {$password}<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); }
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/25 0025 * Time: 上午 10:24 */ require "mysqli_connect.php"; require "common/function.php"; //$sql = "INSERT tg_user SET dg_username=? , dg_password = ?"; //$stmt = mysqli_prepare($conn,$sql); //mysqli_stmt_bind_param($stmt,"ss",$username,$password); $sql = "INSERT tg_user SET dg_username=? , dg_password = ?"; $username = "admin_".time(); $password = sha1("123456"); $type= "INSERT"; mysqli_stmtInsert($conn,$sql,$username,$password,$type);
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/25 0025 * Time: 上午 10:51 */ require "mysqli_connect.php"; require "common/function.php"; $sql = "UPDATE tg_user SET dg_uniqid=? ,dg_question = ? WHERE dg_id>= ?"; $uniqid = "admin_".time(); $question = sha1("123456"); $id=3; $type= "UPDATE"; mysqli_stmtUpdate($conn,$sql,$uniqid,$question,$id,$type);
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/25 0025 * Time: 上午 11:11 */ require "mysqli_connect.php"; require "common/function.php"; $sql = "SELECT dg_username,dg_password FROM tg_user WHERE dg_id> ? "; $id=0; $type= "SELECT"; mysqli_stmtSelect($conn,$sql,$id,$type);
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/25 0025 * Time: 上午 11:05 */ require "mysqli_connect.php"; require "common/function.php"; $sql = "DELETE FROM tg_user WHERE dg_id>= ?"; $id=3; $type= "DELETE"; mysqli_stmtDelete($conn,$sql,$id,$type);
运行实例 »
点击 "运行实例" 按钮查看在线实例