DbConnectionAdapterPgsql.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class LtDbConnectionAdapterPgsql implements LtDbConnectionAdapter
  3. {
  4. public function connect($connConf)
  5. {
  6. if (isset($connConf['pconnect']) && true == $connConf['pconnect'])
  7. {
  8. $func = 'pg_pconnect';
  9. }
  10. else
  11. {
  12. $func = 'pg_connect';
  13. }
  14. return $func("host={$connConf['host']} port={$connConf['port']} user={$connConf['username']} password={$connConf['password']}");
  15. }
  16. public function exec($sql, $connResource)
  17. {
  18. $result = pg_query($connResource, $sql);
  19. return pg_affected_rows($result);
  20. }
  21. public function query($sql, $connResource)
  22. {
  23. $result = pg_query($connResource, $sql);
  24. return pg_fetch_all($result);
  25. }
  26. // SELECT CURRVAL(
  27. // pg_get_serial_sequence('my_tbl_name','id_col_name'));"
  28. // ------------------------------------------------------
  29. // CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
  30. // SELECT lastval();
  31. // $$ LANGUAGE SQL VOLATILE;
  32. public function lastInsertId($connResource)
  33. {
  34. $result = pg_query($connResource, "SELECT lastval()");
  35. $row = pg_fetch_array($result, 0, PGSQL_NUM);
  36. return $row[0];
  37. }
  38. public function escape($sql, $connResource)
  39. {
  40. return pg_escape_string($sql);
  41. }
  42. }