DB.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  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.8.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.8.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 (!count($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.8.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 DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
  831. $level = E_USER_NOTICE, $debuginfo = null)
  832. {
  833. if (is_int($code)) {
  834. $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code,
  835. $mode, $level, $debuginfo);
  836. } else {
  837. $this->PEAR_Error("DB Error: $code", DB_ERROR,
  838. $mode, $level, $debuginfo);
  839. }
  840. }
  841. // }}}
  842. }
  843. // }}}
  844. // {{{ class DB_result
  845. /**
  846. * This class implements a wrapper for a DB result set
  847. *
  848. * A new instance of this class will be returned by the DB implementation
  849. * after processing a query that returns data.
  850. *
  851. * @category Database
  852. * @package DB
  853. * @author Stig Bakken <ssb@php.net>
  854. * @copyright 1997-2007 The PHP Group
  855. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  856. * @version Release: 1.8.2
  857. * @link http://pear.php.net/package/DB
  858. */
  859. class DB_result
  860. {
  861. // {{{ properties
  862. /**
  863. * Should results be freed automatically when there are no more rows?
  864. * @var boolean
  865. * @see DB_common::$options
  866. */
  867. var $autofree;
  868. /**
  869. * A reference to the DB_<driver> object
  870. * @var object
  871. */
  872. var $dbh;
  873. /**
  874. * The current default fetch mode
  875. * @var integer
  876. * @see DB_common::$fetchmode
  877. */
  878. var $fetchmode;
  879. /**
  880. * The name of the class into which results should be fetched when
  881. * DB_FETCHMODE_OBJECT is in effect
  882. *
  883. * @var string
  884. * @see DB_common::$fetchmode_object_class
  885. */
  886. var $fetchmode_object_class;
  887. /**
  888. * The number of rows to fetch from a limit query
  889. * @var integer
  890. */
  891. var $limit_count = null;
  892. /**
  893. * The row to start fetching from in limit queries
  894. * @var integer
  895. */
  896. var $limit_from = null;
  897. /**
  898. * The execute parameters that created this result
  899. * @var array
  900. * @since Property available since Release 1.7.0
  901. */
  902. var $parameters;
  903. /**
  904. * The query string that created this result
  905. *
  906. * Copied here incase it changes in $dbh, which is referenced
  907. *
  908. * @var string
  909. * @since Property available since Release 1.7.0
  910. */
  911. var $query;
  912. /**
  913. * The query result resource id created by PHP
  914. * @var resource
  915. */
  916. var $result;
  917. /**
  918. * The present row being dealt with
  919. * @var integer
  920. */
  921. var $row_counter = null;
  922. /**
  923. * The prepared statement resource id created by PHP in $dbh
  924. *
  925. * This resource is only available when the result set was created using
  926. * a driver's native execute() method, not PEAR DB's emulated one.
  927. *
  928. * Copied here incase it changes in $dbh, which is referenced
  929. *
  930. * {@internal Mainly here because the InterBase/Firebird API is only
  931. * able to retrieve data from result sets if the statemnt handle is
  932. * still in scope.}}
  933. *
  934. * @var resource
  935. * @since Property available since Release 1.7.0
  936. */
  937. var $statement;
  938. // }}}
  939. // {{{ constructor
  940. /**
  941. * This constructor sets the object's properties
  942. *
  943. * @param object &$dbh the DB object reference
  944. * @param resource $result the result resource id
  945. * @param array $options an associative array with result options
  946. *
  947. * @return void
  948. */
  949. function DB_result(&$dbh, $result, $options = array())
  950. {
  951. $this->autofree = $dbh->options['autofree'];
  952. $this->dbh = &$dbh;
  953. $this->fetchmode = $dbh->fetchmode;
  954. $this->fetchmode_object_class = $dbh->fetchmode_object_class;
  955. $this->parameters = $dbh->last_parameters;
  956. $this->query = $dbh->last_query;
  957. $this->result = $result;
  958. $this->statement = empty($dbh->last_stmt) ? null : $dbh->last_stmt;
  959. foreach ($options as $key => $value) {
  960. $this->setOption($key, $value);
  961. }
  962. }
  963. /**
  964. * Set options for the DB_result object
  965. *
  966. * @param string $key the option to set
  967. * @param mixed $value the value to set the option to
  968. *
  969. * @return void
  970. */
  971. function setOption($key, $value = null)
  972. {
  973. switch ($key) {
  974. case 'limit_from':
  975. $this->limit_from = $value;
  976. break;
  977. case 'limit_count':
  978. $this->limit_count = $value;
  979. }
  980. }
  981. // }}}
  982. // {{{ fetchRow()
  983. /**
  984. * Fetch a row of data and return it by reference into an array
  985. *
  986. * The type of array returned can be controlled either by setting this
  987. * method's <var>$fetchmode</var> parameter or by changing the default
  988. * fetch mode setFetchMode() before calling this method.
  989. *
  990. * There are two options for standardizing the information returned
  991. * from databases, ensuring their values are consistent when changing
  992. * DBMS's. These portability options can be turned on when creating a
  993. * new DB object or by using setOption().
  994. *
  995. * + <var>DB_PORTABILITY_LOWERCASE</var>
  996. * convert names of fields to lower case
  997. *
  998. * + <var>DB_PORTABILITY_RTRIM</var>
  999. * right trim the data
  1000. *
  1001. * @param int $fetchmode the constant indicating how to format the data
  1002. * @param int $rownum the row number to fetch (index starts at 0)
  1003. *
  1004. * @return mixed an array or object containing the row's data,
  1005. * NULL when the end of the result set is reached
  1006. * or a DB_Error object on failure.
  1007. *
  1008. * @see DB_common::setOption(), DB_common::setFetchMode()
  1009. */
  1010. function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
  1011. {
  1012. if ($fetchmode === DB_FETCHMODE_DEFAULT) {
  1013. $fetchmode = $this->fetchmode;
  1014. }
  1015. if ($fetchmode === DB_FETCHMODE_OBJECT) {
  1016. $fetchmode = DB_FETCHMODE_ASSOC;
  1017. $object_class = $this->fetchmode_object_class;
  1018. }
  1019. if (is_null($rownum) && $this->limit_from !== null) {
  1020. if ($this->row_counter === null) {
  1021. $this->row_counter = $this->limit_from;
  1022. // Skip rows
  1023. if ($this->dbh->features['limit'] === false) {
  1024. $i = 0;
  1025. while ($i++ < $this->limit_from) {
  1026. $this->dbh->fetchInto($this->result, $arr, $fetchmode);
  1027. }
  1028. }
  1029. }
  1030. if ($this->row_counter >= ($this->limit_from + $this->limit_count))
  1031. {
  1032. if ($this->autofree) {
  1033. $this->free();
  1034. }
  1035. $tmp = null;
  1036. return $tmp;
  1037. }
  1038. if ($this->dbh->features['limit'] === 'emulate') {
  1039. $rownum = $this->row_counter;
  1040. }
  1041. $this->row_counter++;
  1042. }
  1043. $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
  1044. if ($res === DB_OK) {
  1045. if (isset($object_class)) {
  1046. // The default mode is specified in the
  1047. // DB_common::fetchmode_object_class property
  1048. if ($object_class == 'stdClass') {
  1049. $arr = (object) $arr;
  1050. } else {
  1051. $arr = new $object_class($arr);
  1052. }
  1053. }
  1054. return $arr;
  1055. }
  1056. if ($res == null && $this->autofree) {
  1057. $this->free();
  1058. }
  1059. return $res;
  1060. }
  1061. // }}}
  1062. // {{{ fetchInto()
  1063. /**
  1064. * Fetch a row of data into an array which is passed by reference
  1065. *
  1066. * The type of array returned can be controlled either by setting this
  1067. * method's <var>$fetchmode</var> parameter or by changing the default
  1068. * fetch mode setFetchMode() before calling this method.
  1069. *
  1070. * There are two options for standardizing the information returned
  1071. * from databases, ensuring their values are consistent when changing
  1072. * DBMS's. These portability options can be turned on when creating a
  1073. * new DB object or by using setOption().
  1074. *
  1075. * + <var>DB_PORTABILITY_LOWERCASE</var>
  1076. * convert names of fields to lower case
  1077. *
  1078. * + <var>DB_PORTABILITY_RTRIM</var>
  1079. * right trim the data
  1080. *
  1081. * @param array &$arr the variable where the data should be placed
  1082. * @param int $fetchmode the constant indicating how to format the data
  1083. * @param int $rownum the row number to fetch (index starts at 0)
  1084. *
  1085. * @return mixed DB_OK if a row is processed, NULL when the end of the
  1086. * result set is reached or a DB_Error object on failure
  1087. *
  1088. * @see DB_common::setOption(), DB_common::setFetchMode()
  1089. */
  1090. function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
  1091. {
  1092. if ($fetchmode === DB_FETCHMODE_DEFAULT) {
  1093. $fetchmode = $this->fetchmode;
  1094. }
  1095. if ($fetchmode === DB_FETCHMODE_OBJECT) {
  1096. $fetchmode = DB_FETCHMODE_ASSOC;
  1097. $object_class = $this->fetchmode_object_class;
  1098. }
  1099. if (is_null($rownum) && $this->limit_from !== null) {
  1100. if ($this->row_counter === null) {
  1101. $this->row_counter = $this->limit_from;
  1102. // Skip rows
  1103. if ($this->dbh->features['limit'] === false) {
  1104. $i = 0;
  1105. while ($i++ < $this->limit_from) {
  1106. $this->dbh->fetchInto($this->result, $arr, $fetchmode);
  1107. }
  1108. }
  1109. }
  1110. if ($this->row_counter >= (
  1111. $this->limit_from + $this->limit_count))
  1112. {
  1113. if ($this->autofree) {
  1114. $this->free();
  1115. }
  1116. return null;
  1117. }
  1118. if ($this->dbh->features['limit'] === 'emulate') {
  1119. $rownum = $this->row_counter;
  1120. }
  1121. $this->row_counter++;
  1122. }
  1123. $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
  1124. if ($res === DB_OK) {
  1125. if (isset($object_class)) {
  1126. // default mode specified in the
  1127. // DB_common::fetchmode_object_class property
  1128. if ($object_class == 'stdClass') {
  1129. $arr = (object) $arr;
  1130. } else {
  1131. $arr = new $object_class($arr);
  1132. }
  1133. }
  1134. return DB_OK;
  1135. }
  1136. if ($res == null && $this->autofree) {
  1137. $this->free();
  1138. }
  1139. return $res;
  1140. }
  1141. // }}}
  1142. // {{{ numCols()
  1143. /**
  1144. * Get the the number of columns in a result set
  1145. *
  1146. * @return int the number of columns. A DB_Error object on failure.
  1147. */
  1148. function numCols()
  1149. {
  1150. return $this->dbh->numCols($this->result);
  1151. }
  1152. // }}}
  1153. // {{{ numRows()
  1154. /**
  1155. * Get the number of rows in a result set
  1156. *
  1157. * @return int the number of rows. A DB_Error object on failure.
  1158. */
  1159. function numRows()
  1160. {
  1161. if ($this->dbh->features['numrows'] === 'emulate'
  1162. && $this->dbh->options['portability'] & DB_PORTABILITY_NUMROWS)
  1163. {
  1164. if ($this->dbh->features['prepare']) {
  1165. $res = $this->dbh->query($this->query, $this->parameters);
  1166. } else {
  1167. $res = $this->dbh->query($this->query);
  1168. }
  1169. if (DB::isError($res)) {
  1170. return $res;
  1171. }
  1172. $i = 0;
  1173. while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
  1174. $i++;
  1175. }
  1176. $count = $i;
  1177. } else {
  1178. $count = $this->dbh->numRows($this->result);
  1179. }
  1180. /* fbsql is checked for here because limit queries are implemented
  1181. * using a TOP() function, which results in fbsql_num_rows still
  1182. * returning the total number of rows that would have been returned,
  1183. * rather than the real number. As a result, we'll just do the limit
  1184. * calculations for fbsql in the same way as a database with emulated
  1185. * limits. Unfortunately, we can't just do this in DB_fbsql::numRows()
  1186. * because that only gets the result resource, rather than the full
  1187. * DB_Result object. */
  1188. if (($this->dbh->features['limit'] === 'emulate'
  1189. && $this->limit_from !== null)
  1190. || $this->dbh->phptype == 'fbsql') {
  1191. $limit_count = is_null($this->limit_count) ? $count : $this->limit_count;
  1192. if ($count < $this->limit_from) {
  1193. $count = 0;
  1194. } elseif ($count < ($this->limit_from + $limit_count)) {
  1195. $count -= $this->limit_from;
  1196. } else {
  1197. $count = $limit_count;
  1198. }
  1199. }
  1200. return $count;
  1201. }
  1202. // }}}
  1203. // {{{ nextResult()
  1204. /**
  1205. * Get the next result if a batch of queries was executed
  1206. *
  1207. * @return bool true if a new result is available or false if not
  1208. */
  1209. function nextResult()
  1210. {
  1211. return $this->dbh->nextResult($this->result);
  1212. }
  1213. // }}}
  1214. // {{{ free()
  1215. /**
  1216. * Frees the resources allocated for this result set
  1217. *
  1218. * @return bool true on success. A DB_Error object on failure.
  1219. */
  1220. function free()
  1221. {
  1222. $err = $this->dbh->freeResult($this->result);
  1223. if (DB::isError($err)) {
  1224. return $err;
  1225. }
  1226. $this->result = false;
  1227. $this->statement = false;
  1228. return true;
  1229. }
  1230. // }}}
  1231. // {{{ tableInfo()
  1232. /**
  1233. * @see DB_common::tableInfo()
  1234. * @deprecated Method deprecated some time before Release 1.2
  1235. */
  1236. function tableInfo($mode = null)
  1237. {
  1238. if (is_string($mode)) {
  1239. return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
  1240. }
  1241. return $this->dbh->tableInfo($this, $mode);
  1242. }
  1243. // }}}
  1244. // {{{ getQuery()
  1245. /**
  1246. * Determine the query string that created this result
  1247. *
  1248. * @return string the query string
  1249. *
  1250. * @since Method available since Release 1.7.0
  1251. */
  1252. function getQuery()
  1253. {
  1254. return $this->query;
  1255. }
  1256. // }}}
  1257. // {{{ getRowCounter()
  1258. /**
  1259. * Tells which row number is currently being processed
  1260. *
  1261. * @return integer the current row being looked at. Starts at 1.
  1262. */
  1263. function getRowCounter()
  1264. {
  1265. return $this->row_counter;
  1266. }
  1267. // }}}
  1268. }
  1269. // }}}
  1270. // {{{ class DB_row
  1271. /**
  1272. * PEAR DB Row Object
  1273. *
  1274. * The object contains a row of data from a result set. Each column's data
  1275. * is placed in a property named for the column.
  1276. *
  1277. * @category Database
  1278. * @package DB
  1279. * @author Stig Bakken <ssb@php.net>
  1280. * @copyright 1997-2007 The PHP Group
  1281. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  1282. * @version Release: 1.8.2
  1283. * @link http://pear.php.net/package/DB
  1284. * @see DB_common::setFetchMode()
  1285. */
  1286. class DB_row
  1287. {
  1288. // {{{ constructor
  1289. /**
  1290. * The constructor places a row's data into properties of this object
  1291. *
  1292. * @param array the array containing the row's data
  1293. *
  1294. * @return void
  1295. */
  1296. function DB_row(&$arr)
  1297. {
  1298. foreach ($arr as $key => $value) {
  1299. $this->$key = &$arr[$key];
  1300. }
  1301. }
  1302. // }}}
  1303. }
  1304. // }}}
  1305. /*
  1306. * Local variables:
  1307. * tab-width: 4
  1308. * c-basic-offset: 4
  1309. * End:
  1310. */
  1311. ?>