DbiExtension.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /**
  3. * Contract for every database extension supported by phpMyAdmin
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Dbal;
  7. /**
  8. * Contract for every database extension supported by phpMyAdmin
  9. */
  10. interface DbiExtension
  11. {
  12. /**
  13. * connects to the database server
  14. *
  15. * @param string $user user name
  16. * @param string $password user password
  17. * @param array $server host/port/socket/persistent
  18. *
  19. * @return mixed false on error or a connection object on success
  20. */
  21. public function connect(
  22. $user,
  23. $password,
  24. array $server
  25. );
  26. /**
  27. * selects given database
  28. *
  29. * @param string $dbname database name to select
  30. * @param object $link connection object
  31. *
  32. * @return bool
  33. */
  34. public function selectDb($dbname, $link);
  35. /**
  36. * runs a query and returns the result
  37. *
  38. * @param string $query query to execute
  39. * @param object $link connection object
  40. * @param int $options query options
  41. *
  42. * @return mixed result
  43. */
  44. public function realQuery($query, $link, $options);
  45. /**
  46. * Run the multi query and output the results
  47. *
  48. * @param object $link connection object
  49. * @param string $query multi query statement to execute
  50. *
  51. * @return array|bool
  52. */
  53. public function realMultiQuery($link, $query);
  54. /**
  55. * returns array of rows with associative and numeric keys from $result
  56. *
  57. * @param object $result result set identifier
  58. */
  59. public function fetchArray($result): ?array;
  60. /**
  61. * returns array of rows with associative keys from $result
  62. *
  63. * @param object $result result set identifier
  64. */
  65. public function fetchAssoc($result): ?array;
  66. /**
  67. * returns array of rows with numeric keys from $result
  68. *
  69. * @param object $result result set identifier
  70. */
  71. public function fetchRow($result): ?array;
  72. /**
  73. * Adjusts the result pointer to an arbitrary row in the result
  74. *
  75. * @param object $result database result
  76. * @param int $offset offset to seek
  77. *
  78. * @return bool true on success, false on failure
  79. */
  80. public function dataSeek($result, $offset);
  81. /**
  82. * Frees memory associated with the result
  83. *
  84. * @param object $result database result
  85. *
  86. * @return void
  87. */
  88. public function freeResult($result);
  89. /**
  90. * Check if there are any more query results from a multi query
  91. *
  92. * @param object $link the connection object
  93. *
  94. * @return bool true or false
  95. */
  96. public function moreResults($link);
  97. /**
  98. * Prepare next result from multi_query
  99. *
  100. * @param object $link the connection object
  101. *
  102. * @return bool true or false
  103. */
  104. public function nextResult($link);
  105. /**
  106. * Store the result returned from multi query
  107. *
  108. * @param object $link mysql link
  109. *
  110. * @return mixed false when empty results / result set when not empty
  111. */
  112. public function storeResult($link);
  113. /**
  114. * Returns a string representing the type of connection used
  115. *
  116. * @param object $link mysql link
  117. *
  118. * @return string type of connection used
  119. */
  120. public function getHostInfo($link);
  121. /**
  122. * Returns the version of the MySQL protocol used
  123. *
  124. * @param object $link mysql link
  125. *
  126. * @return int|string version of the MySQL protocol used
  127. */
  128. public function getProtoInfo($link);
  129. /**
  130. * returns a string that represents the client library version
  131. *
  132. * @param object $link mysql link
  133. *
  134. * @return string MySQL client library version
  135. */
  136. public function getClientInfo($link);
  137. /**
  138. * returns last error message or false if no errors occurred
  139. *
  140. * @param object $link connection link
  141. *
  142. * @return string|bool error or false
  143. */
  144. public function getError($link);
  145. /**
  146. * returns the number of rows returned by last query
  147. *
  148. * @param object $result result set identifier
  149. *
  150. * @return string|int
  151. */
  152. public function numRows($result);
  153. /**
  154. * returns the number of rows affected by last query
  155. *
  156. * @param object $link the connection object
  157. *
  158. * @return int
  159. */
  160. public function affectedRows($link);
  161. /**
  162. * returns metainfo for fields in $result
  163. *
  164. * @param object $result result set identifier
  165. *
  166. * @return array meta info for fields in $result
  167. */
  168. public function getFieldsMeta($result);
  169. /**
  170. * return number of fields in given $result
  171. *
  172. * @param object $result result set identifier
  173. *
  174. * @return int field count
  175. */
  176. public function numFields($result);
  177. /**
  178. * returns the length of the given field $i in $result
  179. *
  180. * @param object $result result set identifier
  181. * @param int $i field
  182. *
  183. * @return int|bool length of field
  184. */
  185. public function fieldLen($result, $i);
  186. /**
  187. * returns name of $i. field in $result
  188. *
  189. * @param object $result result set identifier
  190. * @param int $i field
  191. *
  192. * @return string name of $i. field in $result
  193. */
  194. public function fieldName($result, $i);
  195. /**
  196. * returns concatenated string of human readable field flags
  197. *
  198. * @param object $result result set identifier
  199. * @param int $i field
  200. *
  201. * @return string field flags
  202. */
  203. public function fieldFlags($result, $i);
  204. /**
  205. * returns properly escaped string for use in MySQL queries
  206. *
  207. * @param mixed $link database link
  208. * @param string $str string to be escaped
  209. *
  210. * @return string a MySQL escaped string
  211. */
  212. public function escapeString($link, $str);
  213. /**
  214. * Prepare an SQL statement for execution.
  215. *
  216. * @param mixed $link database link
  217. * @param string $query The query, as a string.
  218. *
  219. * @return object|false A statement object or false.
  220. */
  221. public function prepare($link, string $query);
  222. }