IDataDriver.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /** @package verysimple::DB::DataDriver */
  3. /**
  4. * IDataDriver is an interface that is used by Phreeze::DataAdapter
  5. * to communicate with a database storage engine. Any server
  6. * that can implement these methods will be usable with
  7. * Phreeze.
  8. *
  9. * @package verysimple::DB::DataDriver
  10. * @author VerySimple Inc. <[email protected]>
  11. * @copyright 1997-2010 VerySimple Inc.
  12. * @license http://www.gnu.org/licenses/lgpl.html LGPL
  13. * @version 1.0
  14. */
  15. interface IDataDriver
  16. {
  17. /**
  18. * returns a string to identify the type of server
  19. * supported in the implemenation
  20. *
  21. * @return string
  22. */
  23. function GetServerType();
  24. /**
  25. * Return true if the given connection is live
  26. * @param $connection
  27. * @return bool;
  28. */
  29. function Ping($connection);
  30. /**
  31. * Open the database with the given parameters. the implementation
  32. * must provide a protocol for the connection string that is relevant
  33. *
  34. * @param string $connectionstring
  35. * @param string $database
  36. * @param string $username
  37. * @param string $password
  38. * @param string $charset the charset that will be used for the connection (example 'utf8')
  39. * @param string $bootstrap SQL that will be executed when the connection is first opened (example 'SET SQL_BIG_SELECTS=1')
  40. * @return connection
  41. */
  42. function Open($connectionstring,$database,$username,$password,$charset='',$bootstrap='');
  43. /**
  44. * Close the given connection reference
  45. * @param connection
  46. */
  47. function Close($connection);
  48. /**
  49. * Execute a SQL query that is expected to return a resultset
  50. * @param connection
  51. * @param string sql query
  52. * @return resultset
  53. */
  54. function Query($connection,$sql);
  55. /**
  56. * Executes a SQL query that does not return a resultset, such as an insert or update
  57. *
  58. * @param connection
  59. * @param string sql statement
  60. * @return int number of affected records
  61. */
  62. function Execute($connection,$sql);
  63. /**
  64. * Moves the database curser forward and returns the current row as an associative array
  65. * When no more data is available, null is returned
  66. *
  67. * @param connection
  68. * @param resultset
  69. * @return array (or null)
  70. */
  71. function Fetch($connection,$rs);
  72. /**
  73. * Returns the last auto-insert id that was inserted for the
  74. * given connection reference
  75. *
  76. * @param connection
  77. */
  78. function GetLastInsertId($connection);
  79. /**
  80. * Returns the last error message that the server encountered
  81. * for the given connection reference
  82. *
  83. * @param connection
  84. */
  85. function GetLastError($connection);
  86. /**
  87. * Releases the resources for the given resultset.
  88. *
  89. * @param connection
  90. * @param resultset
  91. */
  92. function Release($connection,$rs);
  93. /**
  94. * Remove or escape any characters that will cause a SQL statment
  95. * to crash or cause an injection exploit
  96. * @param string value to escape
  97. * @return string value after escaping
  98. */
  99. function Escape($val);
  100. /**
  101. * Return a stringified version of $val ready to insert with appropriate quoting and escaping
  102. * This method must handle at a minimum: strings, numbers, NULL and ISqlFunction objects
  103. * @param variant value to insert/update/query
  104. * @return string value ready to use in a SQL statement quoted and escaped if necessary
  105. */
  106. function GetQuotedSql($val);
  107. /**
  108. * Returns an array of tablenames for the given database
  109. * @param mixed connection reference
  110. * @param string name of the database
  111. * @param $ommitEmptyTables (default false) set to true and tables with no data will be ommitted
  112. */
  113. function GetTableNames($connection, $dbname, $ommitEmptyTables = false) ;
  114. /**
  115. * Optimize, clean, defrag or whatever action is relevant for the database server
  116. * @param mixes connection reference
  117. * @param string name of table to optimize
  118. */
  119. function Optimize($connection,$table);
  120. /**
  121. * Start a database transaction and disable auto-commit if necessary
  122. * @param mixed connection reference
  123. */
  124. function StartTransaction($connection);
  125. /**
  126. * Commit the current database transaction and re-enable auto-commit
  127. * @param mixed connection reference
  128. */
  129. function CommitTransaction($connection);
  130. /**
  131. * Rollback the current database transaction and re-enable auto-commit
  132. * @param mixed connection reference
  133. */
  134. function RollbackTransaction($connection);
  135. }
  136. ?>