PDO连接mysql数据库
时间:2021-07-01 10:21:17
帮助过:4人阅读
代码如下:
<?php
$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();
}
?>
复制代码代码如下:
<?php
$pdo = new PDO("mysql:host=localhost;dbname=db_demo","root","");
$rs = $pdo -> query("select * from test");
while($row = $rs -> fetch()){
print_r($row);
}
?>
PDO连接mysql数据库
标签: