<?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();?>