db.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Public interface of ownCloud for apps to use.
  24. * DB Class
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * This class provides access to the internal database system. Use this class exlusively if you want to access databases
  32. */
  33. class DB {
  34. /**
  35. * @brief Prepare a SQL query
  36. * @param $query Query string
  37. * @returns prepared SQL query
  38. *
  39. * SQL query via MDB2 prepare(), needs to be execute()'d!
  40. */
  41. static public function prepare( $query, $limit=null, $offset=null ) {
  42. return(\OC_DB::prepare($query,$limit,$offset));
  43. }
  44. /**
  45. * @brief gets last value of autoincrement
  46. * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
  47. * @returns id
  48. *
  49. * MDB2 lastInsertID()
  50. *
  51. * Call this method right after the insert command or other functions may
  52. * cause trouble!
  53. */
  54. public static function insertid($table=null) {
  55. return(\OC_DB::insertid($table));
  56. }
  57. /**
  58. * @brief Start a transaction
  59. */
  60. public static function beginTransaction() {
  61. return(\OC_DB::beginTransaction());
  62. }
  63. /**
  64. * @brief Commit the database changes done during a transaction that is in progress
  65. */
  66. public static function commit() {
  67. return(\OC_DB::commit());
  68. }
  69. /**
  70. * @brief check if a result is an error, works with MDB2 and PDOException
  71. * @param mixed $result
  72. * @return bool
  73. */
  74. public static function isError($result) {
  75. return(\OC_DB::isError($result));
  76. }
  77. }