PHP>> PDO>> 返回
项目作者: FaaPz

项目描述 :
Just another PDO database library
高级语言: PHP
项目地址: git://github.com/FaaPz/PDO.git
创建时间: 2015-07-25T17:03:00Z
项目社区:https://github.com/FaaPz/PDO

开源协议:MIT License

下载


PDO

Latest Stable Version
Total Downloads
Latest Unstable Version
License

Just another PDO database library

Installation

Use Composer

  1. $ composer require faapz/pdo

Usage

Examples selecting, inserting, updating and deleting data from or into users table.

  1. require_once 'vendor/autoload.php';
  2. $dsn = 'mysql:host=your_db_host;dbname=your_db_name;charset=utf8';
  3. $usr = 'your_db_username';
  4. $pwd = 'your_db_password';
  5. $database = new FaaPz\PDO\Database($dsn, $usr, $pwd);
  6. // SELECT * FROM users WHERE id = ?
  7. $select = $database->select()
  8. ->from('users')
  9. ->where(new FaaPz\PDO\Clause\Conditional('id', '=', 1234));
  10. if ($insert->execute()) {
  11. $data = $stmt->fetch();
  12. }
  13. // INSERT INTO users (id , username , password) VALUES (? , ? , ?)
  14. $insert = $database->insert(
  15. 'id',
  16. 'username',
  17. 'password'
  18. )
  19. ->into('users')
  20. ->values(
  21. 1234,
  22. 'user',
  23. 'passwd'
  24. );
  25. if ($insert->execute()) {
  26. $insertId = $database->lastInsertId();
  27. }
  28. // UPDATE users SET pwd = ? WHERE id = ?
  29. $update = $database->update(["pwd" => "your_new_password"])
  30. ->table("users")
  31. ->where(new FaaPz\PDO\Clause\Conditional("id", "=", 1234));
  32. if (($result = $update->execute()) !== false) {
  33. $affectedRows = $result->rowCount();
  34. }
  35. // DELETE FROM users WHERE id = ?
  36. $delete = $database->delete()
  37. ->from("users")
  38. ->where(new FaaPz\PDO\Clause\Conditional("id", "=", 1234));
  39. if (($result = $delete->execute()) !== false) {
  40. $affectedRows = $result->rowCount();
  41. }

The sqlsrv extension will fail to connect when using error mode PDO::ERRMODE_EXCEPTION (default). To connect, you will need to explicitly pass array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING) (or PDO::ERRMODE_SILENT) into the constructor, or override the getDefaultOptions() method when using sqlsrv.

Documentation

See DOCUMENTATION

Changelog

See CHANGELOG

License

See LICENSE