Home > Backend Development > PHP Tutorial > php中对MYSQL操作之预处理技术(1)数据库dml操作语句

php中对MYSQL操作之预处理技术(1)数据库dml操作语句

WBOY
Release: 2016-06-23 13:51:52
Original
1072 people have browsed it

<?php//预处理技术//创建一个mysqli对象$mysqli = new MySQLi("主机名","mysql用户名","密码","数据库名");//判断是否链接成功if($mysqli->connect_error){	die($mysqli->connect_error);}//创建预编译对象$sql = "insert into 表名 (name,qq,age) values (?,?,?)";$mysqli_compile = $mysqli->prepare($sql);//绑定参数$name="tao";$qq="12345678";$age="20";//给?处进行赋值,"ssi"指string,string,int,数据类型和顺序一一对应//bind_param()这里参数数目是可变。$mysqli_compile->bind_param("ssi",$name.$qq,$age);//执行语句,返回布尔值$res = $mysqli_compile->execute();//失败打印出原因if(!$res){	die("失败原因=".$mysqli_compile-error);}//关闭资源$musqli->close();?>
Copy after login


 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template