欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php mysql 预编译

程序员文章站 2022-04-18 20:59:27
...
预编译执行 dml 语句

query("set names gbk");
	
	$sql = "insert into user1(name,psw,email,age) values(?,?,?,?)";
	
	$mysqli_stmt = $mysqli->prepare($sql);
	
	//绑定参数
	
	$name = "公子玮";
	$psw = "123";
	$email = "gonziwei.sohu,com";
	$age = 24;

	$mysqli_stmt->bind_param("sssi",$name,$psw,$email,$age);
	
	$b = $mysqli_stmt->execute();
	
	if(!$b){
		die("failed".$mysqli_stmt->error);
		exit();
	}else{
		echo "success
"; } //继续添加 $name = "编程大师"; $psw = "123"; $email = "dashi.sohu,com"; $age = 25; $mysqli_stmt->bind_param("sssi",$name,$psw,$email,$age); $b = $mysqli_stmt->execute(); if(!$b){ die("failed".$mysqli_stmt->error); exit(); }else{ echo "success
"; } //继续添加 $name = "编程屌丝"; $psw = "123"; $email = "diaoshi.sohu,com"; $age = 25; $mysqli_stmt->bind_param("sssi",$name,$psw,$email,$age); $b = $mysqli_stmt->execute(); if(!$b){ die("failed".$mysqli_stmt->error); exit(); }else{ echo "success
"; } $mysqli->close(); ?>

预编译执行 dql 语句:

connect_error){
		die($mysqli->connect_error);
		exit();
	}
	//create a predefined object and get a position
	
	$sql = "select id,name,email from user1 where id > ?";
	
	$mysqli_stmt = $mysqli->prepare($sql);
	$id = 5;
	//bind param
	$mysqli_stmt->bind_param("i",$id);
	
	//bind results
	
	$mysqli_stmt->bind_result($id,$name,$email);
	
	
	$mysqli_stmt->execute();
	
	while ($mysqli_stmt->fetch()){
		echo "--$id--$name--$email
"; } $mysqli_stmt->close(); $mysqli->close(); ?>

以上就介绍了php mysql 预编译,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。