如果你使用了最新版的XAMPP,那么你几乎不用改变php.ini的设置,就可以使用pdo
but,插了一晚上,程序既不报错也不插入数据,真是气死人,后来发现是实例化pdo对象的时候没有指定字符集。所以一定设定字符集属性,否则极有可能插入数据失败
- 一个插入多条数据的例子(用到了事务)
prepare("select userid,username from userlist");$rows->execute();$pdo->beginTransaction();$ret = $rows->fetchAll();//update rbac_user set mypass = ? where userid = ?for($i=0;$iprepare($sql); $statement->bindValue(1,$ret[$i]['userid']); $statement->bindValue(2,$ret[$i]['username']); $statement->bindValue(3,md5($ret[$i]['userid'])); $statement->execute();}$pdo->commit();$pdo=null;
- 插入一条数据
prepare($sql);$userid = 'masterzhang';$username = '张教练';$pwd = md5('masterzhang');$statement->bindValue(1,$userid,PDO::PARAM_STR);$statement->bindvalue(2,$username,PDO::PARAM_STR);$statement->bindvalue(3,$pwd,PDO::PARAM_STR);$statement->execute();?>