DB.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Database independent query interface
  5. *
  6. * PHP version 5
  7. *
  8. * LICENSE: This source file is subject to version 3.0 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category Database
  15. * @package DB
  16. * @author Stig Bakken <ssb@php.net>
  17. * @author Tomas V.V.Cox <cox@idecnet.com>
  18. * @author Daniel Convissor <danielc@php.net>
  19. * @copyright 1997-2007 The PHP Group
  20. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  21. * @version CVS: $Id$
  22. * @link http://pear.php.net/package/DB
  23. */
  24. /**
  25. * Obtain the PEAR class so it can be extended from
  26. */
  27. require_once 'PEAR.php';
  28. // {{{ constants
  29. // {{{ error codes
  30. /**#@+
  31. * One of PEAR DB's portable error codes.
  32. * @see DB_common::errorCode(), DB::errorMessage()
  33. *
  34. * {@internal If you add an error code here, make sure you also add a textual
  35. * version of it in DB::errorMessage().}}
  36. */
  37. /**
  38. * The code returned by many methods upon success
  39. */
  40. define('DB_OK', 1);
  41. /**
  42. * Unkown error
  43. */
  44. define('DB_ERROR', -1);
  45. /**
  46. * Syntax error
  47. */
  48. define('DB_ERROR_SYNTAX', -2);
  49. /**
  50. * Tried to insert a duplicate value into a primary or unique index
  51. */
  52. define('DB_ERROR_CONSTRAINT', -3);
  53. /**
  54. * An identifier in the query refers to a non-existant object
  55. */
  56. define('DB_ERROR_NOT_FOUND', -4);
  57. /**
  58. * Tried to create a duplicate object
  59. */
  60. define('DB_ERROR_ALREADY_EXISTS', -5);
  61. /**
  62. * The current driver does not support the action you attempted
  63. */
  64. define('DB_ERROR_UNSUPPORTED', -6);
  65. /**
  66. * The number of parameters does not match the number of placeholders
  67. */
  68. define('DB_ERROR_MISMATCH', -7);
  69. /**
  70. * A literal submitted did not match the data type expected
  71. */
  72. define('DB_ERROR_INVALID', -8);
  73. /**
  74. * The current DBMS does not support the action you attempted
  75. */
  76. define('DB_ERROR_NOT_CAPABLE', -9);
  77. /**
  78. * A literal submitted was too long so the end of it was removed
  79. */
  80. define('DB_ERROR_TRUNCATED', -10);
  81. /**
  82. * A literal number submitted did not match the data type expected
  83. */
  84. define('DB_ERROR_INVALID_NUMBER', -11);
  85. /**
  86. * A literal date submitted did not match the data type expected
  87. */
  88. define('DB_ERROR_INVALID_DATE', -12);
  89. /**
  90. * Attempt to divide something by zero
  91. */
  92. define('DB_ERROR_DIVZERO', -13);
  93. /**
  94. * A database needs to be selected
  95. */
  96. define('DB_ERROR_NODBSELECTED', -14);
  97. /**
  98. * Could not create the object requested
  99. */
  100. define('DB_ERROR_CANNOT_CREATE', -15);
  101. /**
  102. * Could not drop the database requested because it does not exist
  103. */
  104. define('DB_ERROR_CANNOT_DROP', -17);
  105. /**
  106. * An identifier in the query refers to a non-existant table
  107. */
  108. define('DB_ERROR_NOSUCHTABLE', -18);
  109. /**
  110. * An identifier in the query refers to a non-existant column
  111. */
  112. define('DB_ERROR_NOSUCHFIELD', -19);
  113. /**
  114. * The data submitted to the method was inappropriate
  115. */
  116. define('DB_ERROR_NEED_MORE_DATA', -20);
  117. /**
  118. * The attempt to lock the table failed
  119. */
  120. define('DB_ERROR_NOT_LOCKED', -21);
  121. /**
  122. * The number of columns doesn't match the number of values
  123. */
  124. define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
  125. /**
  126. * The DSN submitted has problems
  127. */
  128. define('DB_ERROR_INVALID_DSN', -23);
  129. /**
  130. * Could not connect to the database
  131. */
  132. define('DB_ERROR_CONNECT_FAILED', -24);
  133. /**
  134. * The PHP extension needed for this DBMS could not be found
  135. */
  136. define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
  137. /**
  138. * The present user has inadequate permissions to perform the task requestd
  139. */
  140. define('DB_ERROR_ACCESS_VIOLATION', -26);
  141. /**
  142. * The database requested does not exist
  143. */
  144. define('DB_ERROR_NOSUCHDB', -27);
  145. /**
  146. * Tried to insert a null value into a column that doesn't allow nulls
  147. */
  148. define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
  149. /**#@-*/
  150. // }}}
  151. // {{{ prepared statement-related
  152. /**#@+
  153. * Identifiers for the placeholders used in prepared statements.
  154. * @see DB_common::prepare()
  155. */
  156. /**
  157. * Indicates a scalar (<kbd>?</kbd>) placeholder was used
  158. *
  159. * Quote and escape the value as necessary.
  160. */
  161. define('DB_PARAM_SCALAR', 1);
  162. /**
  163. * Indicates an opaque (<kbd>&</kbd>) placeholder was used
  164. *
  165. * The value presented is a file name. Extract the contents of that file
  166. * and place them in this column.
  167. */
  168. define('DB_PARAM_OPAQUE', 2);
  169. /**
  170. * Indicates a misc (<kbd>!</kbd>) placeholder was used
  171. *
  172. * The value should not be quoted or escaped.
  173. */
  174. define('DB_PARAM_MISC', 3);
  175. /**#@-*/
  176. // }}}
  177. // {{{ binary data-related
  178. /**#@+
  179. * The different ways of returning binary data from queries.
  180. */
  181. /**
  182. * Sends the fetched data straight through to output
  183. */
  184. define('DB_BINMODE_PASSTHRU', 1);
  185. /**
  186. * Lets you return data as usual
  187. */
  188. define('DB_BINMODE_RETURN', 2);
  189. /**
  190. * Converts the data to hex format before returning it
  191. *
  192. * For example the string "123" would become "313233".
  193. */
  194. define('DB_BINMODE_CONVERT', 3);
  195. /**#@-*/
  196. // }}}
  197. // {{{ fetch modes
  198. /**#@+
  199. * Fetch Modes.
  200. * @see DB_common::setFetchMode()
  201. */
  202. /**
  203. * Indicates the current default fetch mode should be used
  204. * @see DB_common::$fetchmode
  205. */
  206. define('DB_FETCHMODE_DEFAULT', 0);
  207. /**
  208. * Column data indexed by numbers, ordered from 0 and up
  209. */
  210. define('DB_FETCHMODE_ORDERED', 1);
  211. /**
  212. * Column data indexed by column names
  213. */
  214. define('DB_FETCHMODE_ASSOC', 2);
  215. /**
  216. * Column data as object properties
  217. */
  218. define('DB_FETCHMODE_OBJECT', 3);
  219. /**
  220. * For multi-dimensional results, make the column name the first level
  221. * of the array and put the row number in the second level of the array
  222. *
  223. * This is flipped from the normal behavior, which puts the row numbers
  224. * in the first level of the array and the column names in the second level.
  225. */
  226. define('DB_FETCHMODE_FLIPPED', 4);
  227. /**#@-*/
  228. /**#@+
  229. * Old fetch modes. Left here for compatibility.
  230. */
  231. define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
  232. define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
  233. define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
  234. /**#@-*/
  235. // }}}
  236. // {{{ tableInfo() && autoPrepare()-related
  237. /**#@+
  238. * The type of information to return from the tableInfo() method.
  239. *
  240. * Bitwised constants, so they can be combined using <kbd>|</kbd>
  241. * and removed using <kbd>^</kbd>.
  242. *
  243. * @see DB_common::tableInfo()
  244. *
  245. * {@internal Since the TABLEINFO constants are bitwised, if more of them are
  246. * added in the future, make sure to adjust DB_TABLEINFO_FULL accordingly.}}
  247. */
  248. define('DB_TABLEINFO_ORDER', 1);
  249. define('DB_TABLEINFO_ORDERTABLE', 2);
  250. define('DB_TABLEINFO_FULL', 3);
  251. /**#@-*/
  252. /**#@+
  253. * The type of query to create with the automatic query building methods.
  254. * @see DB_common::autoPrepare(), DB_common::autoExecute()
  255. */
  256. define('DB_AUTOQUERY_INSERT', 1);
  257. define('DB_AUTOQUERY_UPDATE', 2);
  258. /**#@-*/
  259. // }}}
  260. // {{{ portability modes
  261. /**#@+
  262. * Portability Modes.
  263. *
  264. * Bitwised constants, so they can be combined using <kbd>|</kbd>
  265. * and removed using <kbd>^</kbd>.
  266. *
  267. * @see DB_common::setOption()
  268. *
  269. * {@internal Since the PORTABILITY constants are bitwised, if more of them are
  270. * added in the future, make sure to adjust DB_PORTABILITY_ALL accordingly.}}
  271. */
  272. /**
  273. * Turn off all portability features
  274. */
  275. define('DB_PORTABILITY_NONE', 0);
  276. /**
  277. * Convert names of tables and fields to lower case
  278. * when using the get*(), fetch*() and tableInfo() methods
  279. */
  280. define('DB_PORTABILITY_LOWERCASE', 1);
  281. /**
  282. * Right trim the data output by get*() and fetch*()
  283. */
  284. define('DB_PORTABILITY_RTRIM', 2);
  285. /**
  286. * Force reporting the number of rows deleted
  287. */
  288. define('DB_PORTABILITY_DELETE_COUNT', 4);
  289. /**
  290. * Enable hack that makes numRows() work in Oracle
  291. */
  292. define('DB_PORTABILITY_NUMROWS', 8);
  293. /**
  294. * Makes certain error messages in certain drivers compatible
  295. * with those from other DBMS's
  296. *
  297. * + mysql, mysqli: change unique/primary key constraints
  298. * DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
  299. *
  300. * + odbc(access): MS's ODBC driver reports 'no such field' as code
  301. * 07001, which means 'too few parameters.' When this option is on
  302. * that code gets mapped to DB_ERROR_NOSUCHFIELD.
  303. */
  304. define('DB_PORTABILITY_ERRORS', 16);
  305. /**
  306. * Convert null values to empty strings in data output by
  307. * get*() and fetch*()
  308. */
  309. define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
  310. /**
  311. * Turn on all portability features
  312. */
  313. define('DB_PORTABILITY_ALL', 63);
  314. /**#@-*/
  315. // }}}
  316. // }}}
  317. // {{{ class DB
  318. /**
  319. * Database independent query interface
  320. *
  321. * The main "DB" class is simply a container class with some static
  322. * methods for creating DB objects as well as some utility functions
  323. * common to all parts of DB.
  324. *
  325. * The object model of DB is as follows (indentation means inheritance):
  326. * <pre>
  327. * DB The main DB class. This is simply a utility class
  328. * with some "static" methods for creating DB objects as
  329. * well as common utility functions for other DB classes.
  330. *
  331. * DB_common The base for each DB implementation. Provides default
  332. * | implementations (in OO lingo virtual methods) for
  333. * | the actual DB implementations as well as a bunch of
  334. * | query utility functions.
  335. * |
  336. * +-DB_mysql The DB implementation for MySQL. Inherits DB_common.
  337. * When calling DB::factory or DB::connect for MySQL
  338. * connections, the object returned is an instance of this
  339. * class.
  340. * </pre>
  341. *
  342. * @category Database
  343. * @package DB
  344. * @author Stig Bakken <ssb@php.net>
  345. * @author Tomas V.V.Cox <cox@idecnet.com>
  346. * @author Daniel Convissor <danielc@php.net>
  347. * @copyright 1997-2007 The PHP Group
  348. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  349. * @version Release: 1.9.2
  350. * @link http://pear.php.net/package/DB
  351. */
  352. class DB
  353. {
  354. // {{{ factory()
  355. /**
  356. * Create a new DB object for the specified database type but don't
  357. * connect to the database
  358. *
  359. * @param string $type the database type (eg "mysql")
  360. * @param array $options an associative array of option names and values
  361. *
  362. * @return object a new DB object. A DB_Error object on failure.
  363. *
  364. * @see DB_common::setOption()
  365. */
  366. public static function factory($type, $options = false)
  367. {
  368. if (!is_array($options)) {
  369. $options = array('persistent' => $options);
  370. }
  371. if (isset($options['debug']) && $options['debug'] >= 2) {
  372. // expose php errors with sufficient debug level
  373. include_once "DB/{$type}.php";
  374. } else {
  375. @include_once "DB/{$type}.php";
  376. }
  377. $classname = "DB_${type}";
  378. if (!class_exists($classname)) {
  379. $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
  380. "Unable to include the DB/{$type}.php"
  381. . " file for '$dsn'",
  382. 'DB_Error', true);
  383. return $tmp;
  384. }
  385. @$obj = new $classname;
  386. foreach ($options as $option => $value) {
  387. $test = $obj->setOption($option, $value);
  388. if (DB::isError($test)) {
  389. return $test;
  390. }
  391. }
  392. return $obj;
  393. }
  394. // }}}
  395. // {{{ connect()
  396. /**
  397. * Create a new DB object including a connection to the specified database
  398. *
  399. * Example 1.
  400. * <code>
  401. * require_once 'DB.php';
  402. *
  403. * $dsn = 'pgsql://user:password@host/database';
  404. * $options = array(
  405. * 'debug' => 2,
  406. * 'portability' => DB_PORTABILITY_ALL,
  407. * );
  408. *
  409. * $db = DB::connect($dsn, $options);
  410. * if (PEAR::isError($db)) {
  411. * die($db->getMessage());
  412. * }
  413. * </code>
  414. *
  415. * @param mixed $dsn the string "data source name" or array in the
  416. * format returned by DB::parseDSN()
  417. * @param array $options an associative array of option names and values
  418. *
  419. * @return object a new DB object. A DB_Error object on failure.
  420. *
  421. * @uses DB_dbase::connect(), DB_fbsql::connect(), DB_ibase::connect(),
  422. * DB_ifx::connect(), DB_msql::connect(), DB_mssql::connect(),
  423. * DB_mysql::connect(), DB_mysqli::connect(), DB_oci8::connect(),
  424. * DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(),
  425. * DB_sybase::connect()
  426. *
  427. * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError()
  428. */
  429. public static function connect($dsn, $options = array())
  430. {
  431. $dsninfo = DB::parseDSN($dsn);
  432. $type = $dsninfo['phptype'];
  433. if (!is_array($options)) {
  434. /*
  435. * For backwards compatibility. $options used to be boolean,
  436. * indicating whether the connection should be persistent.
  437. */
  438. $options = array('persistent' => $options);
  439. }
  440. if (isset($options['debug']) && $options['debug'] >= 2) {
  441. // expose php errors with sufficient debug level
  442. include_once "DB/${type}.php";
  443. } else {
  444. @include_once "DB/${type}.php";
  445. }
  446. $classname = "DB_${type}";
  447. if (!class_exists($classname)) {
  448. $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
  449. "Unable to include the DB/{$type}.php"
  450. . " file for '"
  451. . DB::getDSNString($dsn, true) . "'",
  452. 'DB_Error', true);
  453. return $tmp;
  454. }
  455. @$obj = new $classname;
  456. foreach ($options as $option => $value) {
  457. $test = $obj->setOption($option, $value);
  458. if (DB::isError($test)) {
  459. return $test;
  460. }
  461. }
  462. $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
  463. if (DB::isError($err)) {
  464. if (is_array($dsn)) {
  465. $err->addUserInfo(DB::getDSNString($dsn, true));
  466. } else {
  467. $err->addUserInfo($dsn);
  468. }
  469. return $err;
  470. }
  471. return $obj;
  472. }
  473. // }}}
  474. // {{{ apiVersion()
  475. /**
  476. * Return the DB API version
  477. *
  478. * @return string the DB API version number
  479. */
  480. function apiVersion()
  481. {
  482. return '1.9.2';
  483. }
  484. // }}}
  485. // {{{ isError()
  486. /**
  487. * Determines if a variable is a DB_Error object
  488. *
  489. * @param mixed $value the variable to check
  490. *
  491. * @return bool whether $value is DB_Error object
  492. */
  493. public static function isError($value)
  494. {
  495. return is_object($value) && is_a($value, 'DB_Error');
  496. }
  497. // }}}
  498. // {{{ isConnection()
  499. /**
  500. * Determines if a value is a DB_<driver> object
  501. *
  502. * @param mixed $value the value to test
  503. *
  504. * @return bool whether $value is a DB_<driver> object
  505. */
  506. public static function isConnection($value)
  507. {
  508. return (is_object($value) &&
  509. is_subclass_of($value, 'db_common') &&
  510. method_exists($value, 'simpleQuery'));
  511. }
  512. // }}}
  513. // {{{ isManip()
  514. /**
  515. * Tell whether a query is a data manipulation or data definition query
  516. *
  517. * Examples of data manipulation queries are INSERT, UPDATE and DELETE.
  518. * Examples of data definition queries are CREATE, DROP, ALTER, GRANT,
  519. * REVOKE.
  520. *
  521. * @param string $query the query
  522. *
  523. * @return boolean whether $query is a data manipulation query
  524. */
  525. public static function isManip($query)
  526. {
  527. $manips = 'INSERT|UPDATE|DELETE|REPLACE|'
  528. . 'CREATE|DROP|'
  529. . 'LOAD DATA|SELECT .* INTO .* FROM|COPY|'
  530. . 'ALTER|GRANT|REVOKE|'
  531. . 'LOCK|UNLOCK';
  532. if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
  533. return true;
  534. }
  535. return false;
  536. }
  537. // }}}
  538. // {{{ errorMessage()
  539. /**
  540. * Return a textual error message for a DB error code
  541. *
  542. * @param integer $value the DB error code
  543. *
  544. * @return string the error message or false if the error code was
  545. * not recognized
  546. */
  547. public static function errorMessage($value)
  548. {
  549. static $errorMessages;
  550. if (!isset($errorMessages)) {
  551. $errorMessages = array(
  552. DB_ERROR => 'unknown error',
  553. DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
  554. DB_ERROR_ALREADY_EXISTS => 'already exists',
  555. DB_ERROR_CANNOT_CREATE => 'can not create',
  556. DB_ERROR_CANNOT_DROP => 'can not drop',
  557. DB_ERROR_CONNECT_FAILED => 'connect failed',
  558. DB_ERROR_CONSTRAINT => 'constraint violation',
  559. DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
  560. DB_ERROR_DIVZERO => 'division by zero',
  561. DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
  562. DB_ERROR_INVALID => 'invalid',
  563. DB_ERROR_INVALID_DATE => 'invalid date or time',
  564. DB_ERROR_INVALID_DSN => 'invalid DSN',
  565. DB_ERROR_INVALID_NUMBER => 'invalid number',
  566. DB_ERROR_MISMATCH => 'mismatch',
  567. DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
  568. DB_ERROR_NODBSELECTED => 'no database selected',
  569. DB_ERROR_NOSUCHDB => 'no such database',
  570. DB_ERROR_NOSUCHFIELD => 'no such field',
  571. DB_ERROR_NOSUCHTABLE => 'no such table',
  572. DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
  573. DB_ERROR_NOT_FOUND => 'not found',
  574. DB_ERROR_NOT_LOCKED => 'not locked',
  575. DB_ERROR_SYNTAX => 'syntax error',
  576. DB_ERROR_UNSUPPORTED => 'not supported',
  577. DB_ERROR_TRUNCATED => 'truncated',
  578. DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
  579. DB_OK => 'no error',
  580. );
  581. }
  582. if (DB::isError($value)) {
  583. $value = $value->getCode();
  584. }
  585. return isset($errorMessages[$value]) ? $errorMessages[$value]
  586. : $errorMessages[DB_ERROR];
  587. }
  588. // }}}
  589. // {{{ parseDSN()
  590. /**
  591. * Parse a data source name
  592. *
  593. * Additional keys can be added by appending a URI query string to the
  594. * end of the DSN.
  595. *
  596. * The format of the supplied DSN is in its fullest form:
  597. * <code>
  598. * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
  599. * </code>
  600. *
  601. * Most variations are allowed:
  602. * <code>
  603. * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
  604. * phptype://username:password@hostspec/database_name
  605. * phptype://username:password@hostspec
  606. * phptype://username@hostspec
  607. * phptype://hostspec/database
  608. * phptype://hostspec
  609. * phptype(dbsyntax)
  610. * phptype
  611. * </code>
  612. *
  613. * @param string $dsn Data Source Name to be parsed
  614. *
  615. * @return array an associative array with the following keys:
  616. * + phptype: Database backend used in PHP (mysql, odbc etc.)
  617. * + dbsyntax: Database used with regards to SQL syntax etc.
  618. * + protocol: Communication protocol to use (tcp, unix etc.)
  619. * + hostspec: Host specification (hostname[:port])
  620. * + database: Database to use on the DBMS server
  621. * + username: User name for login
  622. * + password: Password for login
  623. */
  624. public static function parseDSN($dsn)
  625. {
  626. $parsed = array(
  627. 'phptype' => false,
  628. 'dbsyntax' => false,
  629. 'username' => false,
  630. 'password' => false,
  631. 'protocol' => false,
  632. 'hostspec' => false,
  633. 'port' => false,
  634. 'socket' => false,
  635. 'database' => false,
  636. );
  637. if (is_array($dsn)) {
  638. $dsn = array_merge($parsed, $dsn);
  639. if (!$dsn['dbsyntax']) {
  640. $dsn['dbsyntax'] = $dsn['phptype'];
  641. }
  642. return $dsn;
  643. }
  644. // Find phptype and dbsyntax
  645. if (($pos = strpos($dsn, '://')) !== false) {
  646. $str = substr($dsn, 0, $pos);
  647. $dsn = substr($dsn, $pos + 3);
  648. } else {
  649. $str = $dsn;
  650. $dsn = null;
  651. }
  652. // Get phptype and dbsyntax
  653. // $str => phptype(dbsyntax)
  654. if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
  655. $parsed['phptype'] = $arr[1];
  656. $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
  657. } else {
  658. $parsed['phptype'] = $str;
  659. $parsed['dbsyntax'] = $str;
  660. }
  661. if (!strlen($dsn)) {
  662. return $parsed;
  663. }
  664. // Get (if found): username and password
  665. // $dsn => username:password@protocol+hostspec/database
  666. if (($at = strrpos($dsn,'@')) !== false) {
  667. $str = substr($dsn, 0, $at);
  668. $dsn = substr($dsn, $at + 1);
  669. if (($pos = strpos($str, ':')) !== false) {
  670. $parsed['username'] = rawurldecode(substr($str, 0, $pos));
  671. $parsed['password'] = rawurldecode(substr($str, $pos + 1));
  672. } else {
  673. $parsed['username'] = rawurldecode($str);
  674. }
  675. }
  676. // Find protocol and hostspec
  677. if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
  678. // $dsn => proto(proto_opts)/database
  679. $proto = $match[1];
  680. $proto_opts = $match[2] ? $match[2] : false;
  681. $dsn = $match[3];
  682. } else {
  683. // $dsn => protocol+hostspec/database (old format)
  684. if (strpos($dsn, '+') !== false) {
  685. list($proto, $dsn) = explode('+', $dsn, 2);
  686. }
  687. if (strpos($dsn, '/') !== false) {
  688. list($proto_opts, $dsn) = explode('/', $dsn, 2);
  689. } else {
  690. $proto_opts = $dsn;
  691. $dsn = null;
  692. }
  693. }
  694. // process the different protocol options
  695. $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
  696. $proto_opts = rawurldecode($proto_opts);
  697. if (strpos($proto_opts, ':') !== false) {
  698. list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
  699. }
  700. if ($parsed['protocol'] == 'tcp') {
  701. $parsed['hostspec'] = $proto_opts;
  702. } elseif ($parsed['protocol'] == 'unix') {
  703. $parsed['socket'] = $proto_opts;
  704. }
  705. // Get dabase if any
  706. // $dsn => database
  707. if ($dsn) {
  708. if (($pos = strpos($dsn, '?')) === false) {
  709. // /database
  710. $parsed['database'] = rawurldecode($dsn);
  711. } else {
  712. // /database?param1=value1&param2=value2
  713. $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
  714. $dsn = substr($dsn, $pos + 1);
  715. if (strpos($dsn, '&') !== false) {
  716. $opts = explode('&', $dsn);
  717. } else { // database?param1=value1
  718. $opts = array($dsn);
  719. }
  720. foreach ($opts as $opt) {
  721. list($key, $value) = explode('=', $opt);
  722. if (!isset($parsed[$key])) {
  723. // don't allow params overwrite
  724. $parsed[$key] = rawurldecode($value);
  725. }
  726. }
  727. }
  728. }
  729. return $parsed;
  730. }
  731. // }}}
  732. // {{{ getDSNString()
  733. /**
  734. * Returns the given DSN in a string format suitable for output.
  735. *
  736. * @param array|string the DSN to parse and format
  737. * @param boolean true to hide the password, false to include it
  738. * @return string
  739. */
  740. public static function getDSNString($dsn, $hidePassword) {
  741. /* Calling parseDSN will ensure that we have all the array elements
  742. * defined, and means that we deal with strings and array in the same
  743. * manner. */
  744. $dsnArray = DB::parseDSN($dsn);
  745. if ($hidePassword) {
  746. $dsnArray['password'] = 'PASSWORD';
  747. }
  748. /* Protocol is special-cased, as using the default "tcp" along with an
  749. * Oracle TNS connection string fails. */
  750. if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') {
  751. $dsnArray['protocol'] = false;
  752. }
  753. // Now we just have to construct the actual string. This is ugly.
  754. $dsnString = $dsnArray['phptype'];
  755. if ($dsnArray['dbsyntax']) {
  756. $dsnString .= '('.$dsnArray['dbsyntax'].')';
  757. }
  758. $dsnString .= '://'
  759. .$dsnArray['username']
  760. .':'
  761. .$dsnArray['password']
  762. .'@'
  763. .$dsnArray['protocol'];
  764. if ($dsnArray['socket']) {
  765. $dsnString .= '('.$dsnArray['socket'].')';
  766. }
  767. if ($dsnArray['protocol'] && $dsnArray['hostspec']) {
  768. $dsnString .= '+';
  769. }
  770. $dsnString .= $dsnArray['hostspec'];
  771. if ($dsnArray['port']) {
  772. $dsnString .= ':'.$dsnArray['port'];
  773. }
  774. $dsnString .= '/'.$dsnArray['database'];
  775. /* Option handling. Unfortunately, parseDSN simply places options into
  776. * the top-level array, so we'll first get rid of the fields defined by
  777. * DB and see what's left. */
  778. unset($dsnArray['phptype'],
  779. $dsnArray['dbsyntax'],
  780. $dsnArray['username'],
  781. $dsnArray['password'],
  782. $dsnArray['protocol'],
  783. $dsnArray['socket'],
  784. $dsnArray['hostspec'],
  785. $dsnArray['port'],
  786. $dsnArray['database']
  787. );
  788. if (count($dsnArray) > 0) {
  789. $dsnString .= '?';
  790. $i = 0;
  791. foreach ($dsnArray as $key => $value) {
  792. if (++$i > 1) {
  793. $dsnString .= '&';
  794. }
  795. $dsnString .= $key.'='.$value;
  796. }
  797. }
  798. return $dsnString;
  799. }
  800. // }}}
  801. }
  802. // }}}
  803. // {{{ class DB_Error
  804. /**
  805. * DB_Error implements a class for reporting portable database error
  806. * messages
  807. *
  808. * @category Database
  809. * @package DB
  810. * @author Stig Bakken <ssb@php.net>
  811. * @copyright 1997-2007 The PHP Group
  812. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  813. * @version Release: 1.9.2
  814. * @link http://pear.php.net/package/DB
  815. */
  816. class DB_Error extends PEAR_Error
  817. {
  818. // {{{ constructor
  819. /**
  820. * DB_Error constructor
  821. *
  822. * @param mixed $code DB error code, or string with error message
  823. * @param int $mode what "error mode" to operate in
  824. * @param int $level what error level to use for $mode &
  825. * PEAR_ERROR_TRIGGER
  826. * @param mixed $debuginfo additional debug info, such as the last query
  827. *
  828. * @see PEAR_Error
  829. */
  830. function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
  831. $level = E_USER_NOTICE, $debuginfo = null)
  832. {
  833. if (is_int($code)) {
  834. parent::__construct('DB Error: ' . DB::errorMessage($code), $code,
  835. $mode, $level, $debuginfo);
  836. } else {
  837. parent::__construct("DB Error: $code", DB_ERROR,
  838. $mode, $level, $debuginfo);
  839. }
  840. }
  841. /**
  842. * Workaround to both avoid the "Redefining already defined constructor"
  843. * PHP error and provide backward compatibility in case someone is calling
  844. * DB_Error() dynamically
  845. */
  846. public function __call($method, $arguments)
  847. {
  848. if ($method == 'DB_Error') {
  849. return call_user_func_array(array($this, '__construct'), $arguments);
  850. }
  851. trigger_error(
  852. 'Call to undefined method DB_Error::' . $method . '()', E_USER_ERROR
  853. );
  854. }
  855. // }}}
  856. }
  857. // }}}
  858. // {{{ class DB_result
  859. /**
  860. * This class implements a wrapper for a DB result set
  861. *
  862. * A new instance of this class will be returned by the DB implementation
  863. * after processing a query that returns data.
  864. *
  865. * @category Database
  866. * @package DB
  867. * @author Stig Bakken <ssb@php.net>
  868. * @copyright 1997-2007 The PHP Group
  869. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  870. * @version Release: 1.9.2
  871. * @link http://pear.php.net/package/DB
  872. */
  873. class DB_result
  874. {
  875. // {{{ properties
  876. /**
  877. * Should results be freed automatically when there are no more rows?
  878. * @var boolean
  879. * @see DB_common::$options
  880. */
  881. var $autofree;
  882. /**
  883. * A reference to the DB_<driver> object
  884. * @var object
  885. */
  886. var $dbh;
  887. /**
  888. * The current default fetch mode
  889. * @var integer
  890. * @see DB_common::$fetchmode
  891. */
  892. var $fetchmode;
  893. /**
  894. * The name of the class into which results should be fetched when
  895. * DB_FETCHMODE_OBJECT is in effect
  896. *
  897. * @var string
  898. * @see DB_common::$fetchmode_object_class
  899. */
  900. var $fetchmode_object_class;
  901. /**
  902. * The number of rows to fetch from a limit query
  903. * @var integer
  904. */
  905. var $limit_count = null;
  906. /**
  907. * The row to start fetching from in limit queries
  908. * @var integer
  909. */
  910. var $limit_from = null;
  911. /**
  912. * The execute parameters that created this result
  913. * @var array
  914. * @since Property available since Release 1.7.0
  915. */
  916. var $parameters;
  917. /**
  918. * The query string that created this result
  919. *
  920. * Copied here incase it changes in $dbh, which is referenced
  921. *
  922. * @var string
  923. * @since Property available since Release 1.7.0
  924. */
  925. var $query;
  926. /**
  927. * The query result resource id created by PHP
  928. * @var resource
  929. */
  930. var $result;
  931. /**
  932. * The present row being dealt with
  933. * @var integer
  934. */
  935. var $row_counter = null;
  936. /**
  937. * The prepared statement resource id created by PHP in $dbh
  938. *
  939. * This resource is only available when the result set was created using
  940. * a driver's native execute() method, not PEAR DB's emulated one.
  941. *
  942. * Copied here incase it changes in $dbh, which is referenced
  943. *
  944. * {@internal Mainly here because the InterBase/Firebird API is only
  945. * able to retrieve data from result sets if the statemnt handle is
  946. * still in scope.}}
  947. *
  948. * @var resource
  949. * @since Property available since Release 1.7.0
  950. */
  951. var $statement;
  952. // }}}
  953. // {{{ constructor
  954. /**
  955. * This constructor sets the object's properties
  956. *
  957. * @param object &$dbh the DB object reference
  958. * @param resource $result the result resource id
  959. * @param array $options an associative array with result options
  960. *
  961. * @return void
  962. */
  963. function __construct(&$dbh, $result, $options = array())
  964. {
  965. $this->autofree = $dbh->options['autofree'];
  966. $this->dbh = &$dbh;
  967. $this->fetchmode = $dbh->fetchmode;
  968. $this->fetchmode_object_class = $dbh->fetchmode_object_class;
  969. $this->parameters = $dbh->last_parameters;
  970. $this->query = $dbh->last_query;
  971. $this->result = $result;
  972. $this->statement = empty($dbh->last_stmt) ? null : $dbh->last_stmt;
  973. foreach ($options as $key => $value) {
  974. $this->setOption($key, $value);
  975. }
  976. }
  977. /**
  978. * Set options for the DB_result object
  979. *
  980. * @param string $key the option to set
  981. * @param mixed $value the value to set the option to
  982. *
  983. * @return void
  984. */
  985. function setOption($key, $value = null)
  986. {
  987. switch ($key) {
  988. case 'limit_from':
  989. $this->limit_from = $value;
  990. break;
  991. case 'limit_count':
  992. $this->limit_count = $value;
  993. }
  994. }
  995. // }}}
  996. // {{{ fetchRow()
  997. /**
  998. * Fetch a row of data and return it by reference into an array
  999. *
  1000. * The type of array returned can be controlled either by setting this
  1001. * method's <var>$fetchmode</var> parameter or by changing the default
  1002. * fetch mode setFetchMode() before calling this method.
  1003. *
  1004. * There are two options for standardizing the information returned
  1005. * from databases, ensuring their values are consistent when changing
  1006. * DBMS's. These portability options can be turned on when creating a
  1007. * new DB object or by using setOption().
  1008. *
  1009. * + <var>DB_PORTABILITY_LOWERCASE</var>
  1010. * convert names of fields to lower case
  1011. *
  1012. * + <var>DB_PORTABILITY_RTRIM</var>
  1013. * right trim the data
  1014. *
  1015. * @param int $fetchmode the constant indicating how to format the data
  1016. * @param int $rownum the row number to fetch (index starts at 0)
  1017. *
  1018. * @return mixed an array or object containing the row's data,
  1019. * NULL when the end of the result set is reached
  1020. * or a DB_Error object on failure.
  1021. *
  1022. * @see DB_common::setOption(), DB_common::setFetchMode()
  1023. */
  1024. function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
  1025. {
  1026. if ($fetchmode === DB_FETCHMODE_DEFAULT) {
  1027. $fetchmode = $this->fetchmode;
  1028. }
  1029. if ($fetchmode === DB_FETCHMODE_OBJECT) {
  1030. $fetchmode = DB_FETCHMODE_ASSOC;
  1031. $object_class = $this->fetchmode_object_class;
  1032. }
  1033. if (is_null($rownum) && $this->limit_from !== null) {
  1034. if ($this->row_counter === null) {
  1035. $this->row_counter = $this->limit_from;
  1036. // Skip rows
  1037. if ($this->dbh->features['limit'] === false) {
  1038. $i = 0;
  1039. while ($i++ < $this->limit_from) {
  1040. $this->dbh->fetchInto($this->result, $arr, $fetchmode);
  1041. }
  1042. }
  1043. }
  1044. if ($this->row_counter >= ($this->limit_from + $this->limit_count))
  1045. {
  1046. if ($this->autofree) {
  1047. $this->free();
  1048. }
  1049. $tmp = null;
  1050. return $tmp;
  1051. }
  1052. if ($this->dbh->features['limit'] === 'emulate') {
  1053. $rownum = $this->row_counter;
  1054. }
  1055. $this->row_counter++;
  1056. }
  1057. $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
  1058. if ($res === DB_OK) {
  1059. if (isset($object_class)) {
  1060. // The default mode is specified in the
  1061. // DB_common::fetchmode_object_class property
  1062. if ($object_class == 'stdClass') {
  1063. $arr = (object) $arr;
  1064. } else {
  1065. $arr = new $object_class($arr);
  1066. }
  1067. }
  1068. return $arr;
  1069. }
  1070. if ($res == null && $this->autofree) {
  1071. $this->free();
  1072. }
  1073. return $res;
  1074. }
  1075. // }}}
  1076. // {{{ fetchInto()
  1077. /**
  1078. * Fetch a row of data into an array which is passed by reference
  1079. *
  1080. * The type of array returned can be controlled either by setting this
  1081. * method's <var>$fetchmode</var> parameter or by changing the default
  1082. * fetch mode setFetchMode() before calling this method.
  1083. *
  1084. * There are two options for standardizing the information returned
  1085. * from databases, ensuring their values are consistent when changing
  1086. * DBMS's. These portability options can be turned on when creating a
  1087. * new DB object or by using setOption().
  1088. *
  1089. * + <var>DB_PORTABILITY_LOWERCASE</var>
  1090. * convert names of fields to lower case
  1091. *
  1092. * + <var>DB_PORTABILITY_RTRIM</var>
  1093. * right trim the data
  1094. *
  1095. * @param array &$arr the variable where the data should be placed
  1096. * @param int $fetchmode the constant indicating how to format the data
  1097. * @param int $rownum the row number to fetch (index starts at 0)
  1098. *
  1099. * @return mixed DB_OK if a row is processed, NULL when the end of the
  1100. * result set is reached or a DB_Error object on failure
  1101. *
  1102. * @see DB_common::setOption(), DB_common::setFetchMode()
  1103. */
  1104. function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
  1105. {
  1106. if ($fetchmode === DB_FETCHMODE_DEFAULT) {
  1107. $fetchmode = $this->fetchmode;
  1108. }
  1109. if ($fetchmode === DB_FETCHMODE_OBJECT) {
  1110. $fetchmode = DB_FETCHMODE_ASSOC;
  1111. $object_class = $this->fetchmode_object_class;
  1112. }
  1113. if (is_null($rownum) && $this->limit_from !== null) {
  1114. if ($this->row_counter === null) {
  1115. $this->row_counter = $this->limit_from;
  1116. // Skip rows
  1117. if ($this->dbh->features['limit'] === false) {
  1118. $i = 0;
  1119. while ($i++ < $this->limit_from) {
  1120. $this->dbh->fetchInto($this->result, $arr, $fetchmode);
  1121. }
  1122. }
  1123. }
  1124. if ($this->row_counter >= (
  1125. $this->limit_from + $this->limit_count))
  1126. {
  1127. if ($this->autofree) {
  1128. $this->free();
  1129. }
  1130. return null;
  1131. }
  1132. if ($this->dbh->features['limit'] === 'emulate') {
  1133. $rownum = $this->row_counter;
  1134. }
  1135. $this->row_counter++;
  1136. }
  1137. $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
  1138. if ($res === DB_OK) {
  1139. if (isset($object_class)) {
  1140. // default mode specified in the
  1141. // DB_common::fetchmode_object_class property
  1142. if ($object_class == 'stdClass') {
  1143. $arr = (object) $arr;
  1144. } else {
  1145. $arr = new $object_class($arr);
  1146. }
  1147. }
  1148. return DB_OK;
  1149. }
  1150. if ($res == null && $this->autofree) {
  1151. $this->free();
  1152. }
  1153. return $res;
  1154. }
  1155. // }}}
  1156. // {{{ numCols()
  1157. /**
  1158. * Get the the number of columns in a result set
  1159. *
  1160. * @return int the number of columns. A DB_Error object on failure.
  1161. */
  1162. function numCols()
  1163. {
  1164. return $this->dbh->numCols($this->result);
  1165. }
  1166. // }}}
  1167. // {{{ numRows()
  1168. /**
  1169. * Get the number of rows in a result set
  1170. *
  1171. * @return int the number of rows. A DB_Error object on failure.
  1172. */
  1173. function numRows()
  1174. {
  1175. if ($this->dbh->features['numrows'] === 'emulate'
  1176. && $this->dbh->options['portability'] & DB_PORTABILITY_NUMROWS)
  1177. {
  1178. if ($this->dbh->features['prepare']) {
  1179. $res = $this->dbh->query($this->query, $this->parameters);
  1180. } else {
  1181. $res = $this->dbh->query($this->query);
  1182. }
  1183. if (DB::isError($res)) {
  1184. return $res;
  1185. }
  1186. $i = 0;
  1187. while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
  1188. $i++;
  1189. }
  1190. $count = $i;
  1191. } else {
  1192. $count = $this->dbh->numRows($this->result);
  1193. }
  1194. /* fbsql is checked for here because limit queries are implemented
  1195. * using a TOP() function, which results in fbsql_num_rows still
  1196. * returning the total number of rows that would have been returned,
  1197. * rather than the real number. As a result, we'll just do the limit
  1198. * calculations for fbsql in the same way as a database with emulated
  1199. * limits. Unfortunately, we can't just do this in DB_fbsql::numRows()
  1200. * because that only gets the result resource, rather than the full
  1201. * DB_Result object. */
  1202. if (($this->dbh->features['limit'] === 'emulate'
  1203. && $this->limit_from !== null)
  1204. || $this->dbh->phptype == 'fbsql') {
  1205. $limit_count = is_null($this->limit_count) ? $count : $this->limit_count;
  1206. if ($count < $this->limit_from) {
  1207. $count = 0;
  1208. } elseif ($count < ($this->limit_from + $limit_count)) {
  1209. $count -= $this->limit_from;
  1210. } else {
  1211. $count = $limit_count;
  1212. }
  1213. }
  1214. return $count;
  1215. }
  1216. // }}}
  1217. // {{{ nextResult()
  1218. /**
  1219. * Get the next result if a batch of queries was executed
  1220. *
  1221. * @return bool true if a new result is available or false if not
  1222. */
  1223. function nextResult()
  1224. {
  1225. return $this->dbh->nextResult($this->result);
  1226. }
  1227. // }}}
  1228. // {{{ free()
  1229. /**
  1230. * Frees the resources allocated for this result set
  1231. *
  1232. * @return bool true on success. A DB_Error object on failure.
  1233. */
  1234. function free()
  1235. {
  1236. $err = $this->dbh->freeResult($this->result);
  1237. if (DB::isError($err)) {
  1238. return $err;
  1239. }
  1240. $this->result = false;
  1241. $this->statement = false;
  1242. return true;
  1243. }
  1244. // }}}
  1245. // {{{ tableInfo()
  1246. /**
  1247. * @see DB_common::tableInfo()
  1248. * @deprecated Method deprecated some time before Release 1.2
  1249. */
  1250. function tableInfo($mode = null)
  1251. {
  1252. if (is_string($mode)) {
  1253. return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
  1254. }
  1255. return $this->dbh->tableInfo($this, $mode);
  1256. }
  1257. // }}}
  1258. // {{{ getQuery()
  1259. /**
  1260. * Determine the query string that created this result
  1261. *
  1262. * @return string the query string
  1263. *
  1264. * @since Method available since Release 1.7.0
  1265. */
  1266. function getQuery()
  1267. {
  1268. return $this->query;
  1269. }
  1270. // }}}
  1271. // {{{ getRowCounter()
  1272. /**
  1273. * Tells which row number is currently being processed
  1274. *
  1275. * @return integer the current row being looked at. Starts at 1.
  1276. */
  1277. function getRowCounter()
  1278. {
  1279. return $this->row_counter;
  1280. }
  1281. // }}}
  1282. }
  1283. // }}}
  1284. // {{{ class DB_row
  1285. /**
  1286. * PEAR DB Row Object
  1287. *
  1288. * The object contains a row of data from a result set. Each column's data
  1289. * is placed in a property named for the column.
  1290. *
  1291. * @category Database
  1292. * @package DB
  1293. * @author Stig Bakken <ssb@php.net>
  1294. * @copyright 1997-2007 The PHP Group
  1295. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  1296. * @version Release: 1.9.2
  1297. * @link http://pear.php.net/package/DB
  1298. * @see DB_common::setFetchMode()
  1299. */
  1300. class DB_row
  1301. {
  1302. // {{{ constructor
  1303. /**
  1304. * The constructor places a row's data into properties of this object
  1305. *
  1306. * @param array the array containing the row's data
  1307. *
  1308. * @return void
  1309. */
  1310. function __construct(&$arr)
  1311. {
  1312. foreach ($arr as $key => $value) {
  1313. $this->$key = &$arr[$key];
  1314. }
  1315. }
  1316. // }}}
  1317. }
  1318. // }}}
  1319. /*
  1320. * Local variables:
  1321. * tab-width: 4
  1322. * c-basic-offset: 4
  1323. * End:
  1324. */
  1325. ?>