php pdo操作mysql数据库
连接mysql
$db = new PDO('mysql:host=localhost;dbname=mydb;charset=utf8', 'root', '');
操作数据库
$rs = $db->prepare('SELECT * FROM pre_member m LEFT JOIN pre_group g ON m.groupid=g.gid WHERE m.username=:username');
$rs->execute(array(':username' => $username));
//fetchObject()
while($row = $rs->fetch()) {
//...
}
注意
//每次操作完之后都要关闭游标,否则下次运行sql语句的时候会出现问题。
$rs->closeCursor();