<?php
try{
$pdo=new PDO("mysql:host=localhost;dbname=bookstore","root","158369");
echo "数据库连接成功!<br>";
}
catch(PDOexception $e){
echo "数据库连接失败!".$e->getmessage()."<br>";
}
try{
//1.传统的方式:将SQL发给数据库系统并直接执行
//$pdo->exec("insert into salary(name,age,education,salary)values('liu',23,'high',2222)");
/*2.最简单的方式来执行SQL语句:pdo类中的execute方法中传一个数组参数来赋值,建议使用这种方式
$statme=$pdo->prepare("insert into salary(name,age,educatino,salary)values(:name,:age,:education,:salary)");
//与上面名称索引一一对应
$statme->execute(array("name"=>"liuhui3","age"=>"32","education"=>"Junior","salary"=>"2234"));
*/
//通过索引参数一样能赋值
$statme=$pdo->prepare("insert into salary(name,age,educatino,salary)values(?,?,?,?)");
$statme->execute(array("liuhui4","3","Junior","3334"));
echo "数据插入成功!<br>";
}
catch(PDOexception $e){
echo "数据插入失败!".$e->getmessage();
}
?>
原文链接:https://blog.csdn.net/living_ren/article/details/77648973
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~