通用

  1. $dsn = 'mysql:dbname='.$database.';host='.$hostname.':'.$hostport;
  2. $db = new PDO($dsn, $user, $password);
  3. $sql = 'select * from bre_users where user_id = :user_id';
  4. $sth = $db->prepare($sql);
  5. $sth->bindParam(':user_id', $uid, PDO::PARAM_INT);
  6. $sth->execute();

获取一条记录

  1. $sth->fetch(PDO::FETCH_ASSOC);

获取所有记录

  1. $sth->fetchAll(PDO::FETCH_ASSOC);