这是一款利用php+pdo+mysql的操作实例,就是利用pdo连接数据库与查询与保存数据到mysql中呢,pdo数据保存,代码如下:
- <?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);
- }
- ?>
|