//实例化PDO类 连接数据库 参数是 mysql:host=localhost;dbname=lamp 用户名 密码 $pdo = new PDO('mysql:host=localhost;dbname=lamp', 'root', '');
//查询语句
$sql = "select * from lamp_login"; $stmt = $pdo->query($sql);
//增 删 改
$pdo->exec($sql);
PDO::FETCH_OBJ相当于mysql_fetch_object
object(stdClass)[3] public 'id' => string '1' (length=1) public 'username' => string 'user1' (length=5) public 'password' => string '123' (length=3)PDO::FETCH_BOTH相当于mysql_fetch_array
array (size=6) 'id' => string '2' (length=1) 0 => string '2' (length=1) 'username' => string 'user2' (length=5) 1 => string 'user2' (length=5) 'password' => string '234' (length=3) 2 => string '234' (length=3)PDO::FETCH_NUM相当于mysql_fetch_row
array (size=3) 0 => string '3' (length=1) 1 => string 'user3' (length=5) 2 => string '345' (length=3)PDO::FETCH_ASSOC相当于mysql_fetch_assoc
array (size=3) 'id' => string '4' (length=1) 'username' => string 'zhouyao' (length=7) 'password' => string '123456' (length=6)
MySQL PDO连接与操作
最新推荐文章于 2021-02-07 11:20:30 发布