• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php mysql 预编译

php 搞代码 3年前 (2022-01-23) 22次浏览 已收录 0个评论

预编译执行 dml 语句

<?php//mysql预编译	$mysqli = new mysqli("localhost", "root", "root", "php");		$mysqli->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 语句:

<?php	//预编译 执行 dql 语句	header("Content-type:text/html;charset=utf-8");	$mysqli = new mysqli("localhost", "root", "root", "php");		if($mysqli->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(); ?>

@本文来源gaodai$ma#com搞$代*码6网搞代gaodaima码

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php mysql 预编译
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址