Blogger Information
Blog 30
fans 0
comment 0
visits 22457
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
8.30pdo
归宿的博客
Original
766 people have browsed it
  1. mysqli面向对象中的查询操作

$dns = 'mysql:host=127.0.0.1;dbname=php';  //数据源:设置数据库的类型
$user = 'root';    //用户名
$pass = 'root';     //密码
//实例化pdo类,创建pdo对象,并完成了数据库的连接
try{  //判断
    $pdo = new PDO($dns,$user,$pass);
    echo '连接成功';
}catch (PDOException $e){
    die('连接错误'.$e->getMessage());
}

    2.pdo的优势:

    pdo是php处理所有数据提供的一个统一访问接口;

    3.pdo连接数据库

$pdo = new PDO('mysql:host=127.0.0.1;dbname=php','root','root');

    4.pdo新增数据

"INSERT INTO `user` SET `name`= :name,`email`=:email,`password`=sha1(:password)";

     5.pdo更新数据

"UPDATE `user` SET `email`=:email WHERE `id`=:id";

    6.pdo删除数据

"DELETE FROM `user` WHERE `id`=:id";

    7.pdo查询数据

$sql = "SELECT `name`,`email` FROM `user` WHERE `id`<:id";

    8.获取结果集的正确方式是:

$stmt->fetchColumn();


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post