PDO预处理语句

1.造PDO对象
$dsn = "mysql:dbname=mydb;host=localhost";
$pdo = new PDO($dsn,"root","123");

2.写一个预处理语句
$sql = "insert into nation values(?,?)";

3.将预处理语句扔到服务器等待执行,返回PDOStatement对象
$stm = $pdo->prepare($sql);

4.第二次将变量(参数)扔到服务器的SQL语句相应位置,给预处理语句绑定参数
$stm->bindParam(1,$code);
$stm->bindParam(2,$name);
$code = "n085";
$name = "天族";

5.定义索引数组
$arr = array("n082","数据");

6.执行
$stm->execute($arr);


1.造PDO对象
$dsn = "mysql:dbname=mydb;host=localhost";
$pdo = new PDO($dsn,"root","123"); 2.预处理语句
$sql = "insert into nation values(:code,:name)";
$stm = $pdo->prepare($sql); 3.绑定参数
$stm->bindParam(":code",$code);
$stm->bindParam(":name",$name);
$code = "n070";
$name = "神族"; 4.造一个数组
$arr = array("code"=>"n071","name"=>"胜率"); 5.执行
$stm->execute($arr);


上一篇:快速理解Java中的七种单例模式


下一篇:Android学习总结——SQLite