首页 > Web开发 > 详细

PHP中pdo的使用

时间:2017-11-16 10:51:08      阅读:230      评论:0      收藏:0      [点我收藏+]

<?php
/**
*下面代码中information为表名
*
*/
//1.先要连数据库
$pdo=new PDO(‘mysql:host=localhost;dbname=数据库名‘,‘用户‘,‘密码‘);
// $pdo=new PDO(‘mysql:host=localhost;dbname=数据库名‘,‘一般是root‘,‘一般为空不填‘);对于新手不会配置的
//query语句的查询
// $state=$pdo->query(‘select * from information‘);
// $stmt=$state->fetchAll(PDO::FETCH_ASSOC);
// var_dump($stmt);

 


//exec语句的增
// $affected=$pdo->exec(‘insert into information (name,sex) values("pp",15)‘);
// var_dump($affected);

//改
// $res=$pdo->exec(‘update information set name="pps" where name="pp"‘);

//删
// $res=$pdo->exec(‘delete from information where name="pps"‘);
// var_dump($res);

 

 

 

 

//prepare语句的增
// $stmt=$pdo->prepare(‘insert into information (name,sex) values(:name,:sex)‘);
// $arr=array(
// ‘name‘=>"pipixia",
// ‘sex‘=>‘20‘
// );
// $res=$stmt->execute($arr);

//改
// $stmt=$pdo->prepare(‘update information set name = :name where id = :id‘);
// $arr=array(
// ‘name‘=>"pps",
// ‘id‘=>10
// );
// $res=$stmt->execute($arr);


//删
// $stmt=$pdo->prepare(‘delete from information where id=:id‘);
// $arr=array(
// ‘id‘=>10
// );
// $res=$stmt->execute($arr);

//查
// $query = $pdo->prepare("select * from information");
// $query->execute();
// $row = $query->fetchAll(PDO::FETCH_ASSOC);
// var_dump($row);

 

PHP中pdo的使用

原文:http://www.cnblogs.com/dyj--php/p/7842892.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!