pdo连接数据库与查询与保存数据到mysql

作者:袖梨 2022-07-02

pdo数据保存

 代码如下 复制代码
$pdo = new pdo("mysql:host=localhost;dbname=db_demo","root","");
if($pdo -> exec("insert into db_demo(name,content) values('title','content')")){
echo "插入成功!";
echo $pdo -> lastinsertid();
}
?>

查询数据库

 代码如下 复制代码
$pdo = new pdo("mysql:host=localhost;dbname=db_demo","root","");
$rs = $pdo -> query("select * from test");
while($row = $rs -> fetch()){
print_r($row);
}
?>

相关文章

精彩推荐