时间:2021-07-01 10:21:17 帮助过:19人阅读
//实例化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连接与操作,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。