DB.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  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 = [])
  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. * Determines if a variable is a DB_Error object
  398. *
  399. * @param mixed $value the variable to check
  400. *
  401. * @return bool whether $value is DB_Error object
  402. */
  403. public static function isError($value)
  404. {
  405. return is_object($value) && is_a($value, 'DB_Error');
  406. }
  407. // }}}
  408. // {{{ apiVersion()
  409. /**
  410. * Create a new DB object including a connection to the specified database
  411. *
  412. * Example 1.
  413. * <code>
  414. * require_once 'DB.php';
  415. *
  416. * $dsn = 'pgsql://user:password@host/database';
  417. * $options = array(
  418. * 'debug' => 2,
  419. * 'portability' => DB_PORTABILITY_ALL,
  420. * );
  421. *
  422. * $db = DB::connect($dsn, $options);
  423. * if (PEAR::isError($db)) {
  424. * die($db->getMessage());
  425. * }
  426. * </code>
  427. *
  428. * @param mixed $dsn the string "data source name" or array in the
  429. * format returned by DB::parseDSN()
  430. * @param array $options an associative array of option names and values
  431. *
  432. * @return object a new DB object. A DB_Error object on failure.
  433. *
  434. * @uses DB_dbase::connect(), DB_fbsql::connect(), DB_ibase::connect(),
  435. * DB_ifx::connect(), DB_msql::connect(), DB_mssql::connect(),
  436. * DB_mysql::connect(), DB_mysqli::connect(), DB_oci8::connect(),
  437. * DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(),
  438. * DB_sybase::connect()
  439. *
  440. * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError()
  441. */
  442. public static function connect($dsn, $options = array())
  443. {
  444. $dsninfo = DB::parseDSN($dsn);
  445. $type = $dsninfo['phptype'];
  446. if (!is_array($options)) {
  447. /*
  448. * For backwards compatibility. $options used to be boolean,
  449. * indicating whether the connection should be persistent.
  450. */
  451. $options = array('persistent' => $options);
  452. }
  453. if (isset($options['debug']) && $options['debug'] >= 2) {
  454. // expose php errors with sufficient debug level
  455. include_once "DB/${type}.php";
  456. } else {
  457. @include_once "DB/${type}.php";
  458. }
  459. $classname = "DB_${type}";
  460. if (!class_exists($classname)) {
  461. $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
  462. "Unable to include the DB/{$type}.php"
  463. . " file for '"
  464. . DB::getDSNString($dsn, true) . "'",
  465. 'DB_Error', true);
  466. return $tmp;
  467. }
  468. @$obj = new $classname;
  469. foreach ($options as $option => $value) {
  470. $test = $obj->setOption($option, $value);
  471. if (DB::isError($test)) {
  472. return $test;
  473. }
  474. }
  475. $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
  476. if (DB::isError($err)) {
  477. if (is_array($dsn)) {
  478. $err->addUserInfo(DB::getDSNString($dsn, true));
  479. } else {
  480. $err->addUserInfo($dsn);
  481. }
  482. return $err;
  483. }
  484. return $obj;
  485. }
  486. // }}}
  487. // {{{ isError()
  488. /**
  489. * Parse a data source name
  490. *
  491. * Additional keys can be added by appending a URI query string to the
  492. * end of the DSN.
  493. *
  494. * The format of the supplied DSN is in its fullest form:
  495. * <code>
  496. * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
  497. * </code>
  498. *
  499. * Most variations are allowed:
  500. * <code>
  501. * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
  502. * phptype://username:password@hostspec/database_name
  503. * phptype://username:password@hostspec
  504. * phptype://username@hostspec
  505. * phptype://hostspec/database
  506. * phptype://hostspec
  507. * phptype(dbsyntax)
  508. * phptype
  509. * </code>
  510. *
  511. * @param string $dsn Data Source Name to be parsed
  512. *
  513. * @return array an associative array with the following keys:
  514. * + phptype: Database backend used in PHP (mysql, odbc etc.)
  515. * + dbsyntax: Database used with regards to SQL syntax etc.
  516. * + protocol: Communication protocol to use (tcp, unix etc.)
  517. * + hostspec: Host specification (hostname[:port])
  518. * + database: Database to use on the DBMS server
  519. * + username: User name for login
  520. * + password: Password for login
  521. */
  522. public static function parseDSN($dsn)
  523. {
  524. $parsed = array(
  525. 'phptype' => false,
  526. 'dbsyntax' => false,
  527. 'username' => false,
  528. 'password' => false,
  529. 'protocol' => false,
  530. 'hostspec' => false,
  531. 'port' => false,
  532. 'socket' => false,
  533. 'database' => false,
  534. );
  535. if (is_array($dsn)) {
  536. $dsn = array_merge($parsed, $dsn);
  537. if (!$dsn['dbsyntax']) {
  538. $dsn['dbsyntax'] = $dsn['phptype'];
  539. }
  540. return $dsn;
  541. }
  542. // Find phptype and dbsyntax
  543. if (($pos = strpos($dsn, '://')) !== false) {
  544. $str = substr($dsn, 0, $pos);
  545. $dsn = substr($dsn, $pos + 3);
  546. } else {
  547. $str = $dsn;
  548. $dsn = null;
  549. }
  550. // Get phptype and dbsyntax
  551. // $str => phptype(dbsyntax)
  552. if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
  553. $parsed['phptype'] = $arr[1];
  554. $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
  555. } else {
  556. $parsed['phptype'] = $str;
  557. $parsed['dbsyntax'] = $str;
  558. }
  559. if (!strlen($dsn)) {
  560. return $parsed;
  561. }
  562. // Get (if found): username and password
  563. // $dsn => username:password@protocol+hostspec/database
  564. if (($at = strrpos($dsn, '@')) !== false) {
  565. $str = substr($dsn, 0, $at);
  566. $dsn = substr($dsn, $at + 1);
  567. if (($pos = strpos($str, ':')) !== false) {
  568. $parsed['username'] = rawurldecode(substr($str, 0, $pos));
  569. $parsed['password'] = rawurldecode(substr($str, $pos + 1));
  570. } else {
  571. $parsed['username'] = rawurldecode($str);
  572. }
  573. }
  574. // Find protocol and hostspec
  575. if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
  576. // $dsn => proto(proto_opts)/database
  577. $proto = $match[1];
  578. $proto_opts = $match[2] ? $match[2] : false;
  579. $dsn = $match[3];
  580. } else {
  581. // $dsn => protocol+hostspec/database (old format)
  582. if (strpos($dsn, '+') !== false) {
  583. list($proto, $dsn) = explode('+', $dsn, 2);
  584. }
  585. if (strpos($dsn, '/') !== false) {
  586. list($proto_opts, $dsn) = explode('/', $dsn, 2);
  587. } else {
  588. $proto_opts = $dsn;
  589. $dsn = null;
  590. }
  591. }
  592. // process the different protocol options
  593. $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
  594. $proto_opts = rawurldecode($proto_opts);
  595. if (strpos($proto_opts, ':') !== false) {
  596. list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
  597. }
  598. if ($parsed['protocol'] == 'tcp') {
  599. $parsed['hostspec'] = $proto_opts;
  600. } elseif ($parsed['protocol'] == 'unix') {
  601. $parsed['socket'] = $proto_opts;
  602. }
  603. // Get dabase if any
  604. // $dsn => database
  605. if ($dsn) {
  606. if (($pos = strpos($dsn, '?')) === false) {
  607. // /database
  608. $parsed['database'] = rawurldecode($dsn);
  609. } else {
  610. // /database?param1=value1&param2=value2
  611. $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
  612. $dsn = substr($dsn, $pos + 1);
  613. if (strpos($dsn, '&') !== false) {
  614. $opts = explode('&', $dsn);
  615. } else { // database?param1=value1
  616. $opts = array($dsn);
  617. }
  618. foreach ($opts as $opt) {
  619. list($key, $value) = explode('=', $opt);
  620. if (!isset($parsed[$key])) {
  621. // don't allow params overwrite
  622. $parsed[$key] = rawurldecode($value);
  623. }
  624. }
  625. }
  626. }
  627. return $parsed;
  628. }
  629. // }}}
  630. // {{{ isConnection()
  631. /**
  632. * Returns the given DSN in a string format suitable for output.
  633. *
  634. * @param array|string the DSN to parse and format
  635. * @param boolean true to hide the password, false to include it
  636. * @return string
  637. */
  638. public static function getDSNString($dsn, $hidePassword)
  639. {
  640. /* Calling parseDSN will ensure that we have all the array elements
  641. * defined, and means that we deal with strings and array in the same
  642. * manner. */
  643. $dsnArray = DB::parseDSN($dsn);
  644. if ($hidePassword) {
  645. $dsnArray['password'] = 'PASSWORD';
  646. }
  647. /* Protocol is special-cased, as using the default "tcp" along with an
  648. * Oracle TNS connection string fails. */
  649. if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') {
  650. $dsnArray['protocol'] = false;
  651. }
  652. // Now we just have to construct the actual string. This is ugly.
  653. $dsnString = $dsnArray['phptype'];
  654. if ($dsnArray['dbsyntax']) {
  655. $dsnString .= '(' . $dsnArray['dbsyntax'] . ')';
  656. }
  657. $dsnString .= '://'
  658. . $dsnArray['username']
  659. . ':'
  660. . $dsnArray['password']
  661. . '@'
  662. . $dsnArray['protocol'];
  663. if ($dsnArray['socket']) {
  664. $dsnString .= '(' . $dsnArray['socket'] . ')';
  665. }
  666. if ($dsnArray['protocol'] && $dsnArray['hostspec']) {
  667. $dsnString .= '+';
  668. }
  669. $dsnString .= $dsnArray['hostspec'];
  670. if ($dsnArray['port']) {
  671. $dsnString .= ':' . $dsnArray['port'];
  672. }
  673. $dsnString .= '/' . $dsnArray['database'];
  674. /* Option handling. Unfortunately, parseDSN simply places options into
  675. * the top-level array, so we'll first get rid of the fields defined by
  676. * DB and see what's left. */
  677. unset($dsnArray['phptype'],
  678. $dsnArray['dbsyntax'],
  679. $dsnArray['username'],
  680. $dsnArray['password'],
  681. $dsnArray['protocol'],
  682. $dsnArray['socket'],
  683. $dsnArray['hostspec'],
  684. $dsnArray['port'],
  685. $dsnArray['database']
  686. );
  687. if (count($dsnArray) > 0) {
  688. $dsnString .= '?';
  689. $i = 0;
  690. foreach ($dsnArray as $key => $value) {
  691. if (++$i > 1) {
  692. $dsnString .= '&';
  693. }
  694. $dsnString .= $key . '=' . $value;
  695. }
  696. }
  697. return $dsnString;
  698. }
  699. // }}}
  700. // {{{ isManip()
  701. /**
  702. * Determines if a value is a DB_<driver> object
  703. *
  704. * @param mixed $value the value to test
  705. *
  706. * @return bool whether $value is a DB_<driver> object
  707. */
  708. public static function isConnection($value)
  709. {
  710. return (is_object($value) &&
  711. is_subclass_of($value, 'db_common') &&
  712. method_exists($value, 'simpleQuery'));
  713. }
  714. // }}}
  715. // {{{ errorMessage()
  716. /**
  717. * Tell whether a query is a data manipulation or data definition query
  718. *
  719. * Examples of data manipulation queries are INSERT, UPDATE and DELETE.
  720. * Examples of data definition queries are CREATE, DROP, ALTER, GRANT,
  721. * REVOKE.
  722. *
  723. * @param string $query the query
  724. *
  725. * @return boolean whether $query is a data manipulation query
  726. */
  727. public static function isManip($query)
  728. {
  729. $manips = 'INSERT|UPDATE|DELETE|REPLACE|'
  730. . 'CREATE|DROP|'
  731. . 'LOAD DATA|SELECT .* INTO .* FROM|COPY|'
  732. . 'ALTER|GRANT|REVOKE|'
  733. . 'LOCK|UNLOCK';
  734. if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
  735. return true;
  736. }
  737. return false;
  738. }
  739. // }}}
  740. // {{{ parseDSN()
  741. /**
  742. * Return a textual error message for a DB error code
  743. *
  744. * @param integer $value the DB error code
  745. *
  746. * @return string the error message or false if the error code was
  747. * not recognized
  748. */
  749. public static function errorMessage($value)
  750. {
  751. static $errorMessages;
  752. if (!isset($errorMessages)) {
  753. $errorMessages = array(
  754. DB_ERROR => 'unknown error',
  755. DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
  756. DB_ERROR_ALREADY_EXISTS => 'already exists',
  757. DB_ERROR_CANNOT_CREATE => 'can not create',
  758. DB_ERROR_CANNOT_DROP => 'can not drop',
  759. DB_ERROR_CONNECT_FAILED => 'connect failed',
  760. DB_ERROR_CONSTRAINT => 'constraint violation',
  761. DB_ERROR_CONSTRAINT_NOT_NULL => 'null value violates not-null constraint',
  762. DB_ERROR_DIVZERO => 'division by zero',
  763. DB_ERROR_EXTENSION_NOT_FOUND => 'extension not found',
  764. DB_ERROR_INVALID => 'invalid',
  765. DB_ERROR_INVALID_DATE => 'invalid date or time',
  766. DB_ERROR_INVALID_DSN => 'invalid DSN',
  767. DB_ERROR_INVALID_NUMBER => 'invalid number',
  768. DB_ERROR_MISMATCH => 'mismatch',
  769. DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
  770. DB_ERROR_NODBSELECTED => 'no database selected',
  771. DB_ERROR_NOSUCHDB => 'no such database',
  772. DB_ERROR_NOSUCHFIELD => 'no such field',
  773. DB_ERROR_NOSUCHTABLE => 'no such table',
  774. DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
  775. DB_ERROR_NOT_FOUND => 'not found',
  776. DB_ERROR_NOT_LOCKED => 'not locked',
  777. DB_ERROR_SYNTAX => 'syntax error',
  778. DB_ERROR_UNSUPPORTED => 'not supported',
  779. DB_ERROR_TRUNCATED => 'truncated',
  780. DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
  781. DB_OK => 'no error',
  782. );
  783. }
  784. if (DB::isError($value)) {
  785. $value = $value->getCode();
  786. }
  787. return isset($errorMessages[$value]) ? $errorMessages[$value]
  788. : $errorMessages[DB_ERROR];
  789. }
  790. // }}}
  791. // {{{ getDSNString()
  792. /**
  793. * Return the DB API version
  794. *
  795. * @return string the DB API version number
  796. */
  797. function apiVersion()
  798. {
  799. return '1.9.2';
  800. }
  801. // }}}
  802. }
  803. // }}}
  804. // {{{ class DB_Error
  805. /**
  806. * DB_Error implements a class for reporting portable database error
  807. * messages
  808. *
  809. * @category Database
  810. * @package DB
  811. * @author Stig Bakken <ssb@php.net>
  812. * @copyright 1997-2007 The PHP Group
  813. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  814. * @version Release: 1.9.2
  815. * @link http://pear.php.net/package/DB
  816. */
  817. class DB_Error extends PEAR_Error
  818. {
  819. // {{{ constructor
  820. /**
  821. * DB_Error constructor
  822. *
  823. * @param mixed $code DB error code, or string with error message
  824. * @param int $mode what "error mode" to operate in
  825. * @param int $level what error level to use for $mode &
  826. * PEAR_ERROR_TRIGGER
  827. * @param mixed $debuginfo additional debug info, such as the last query
  828. *
  829. * @see PEAR_Error
  830. */
  831. function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
  832. $level = E_USER_NOTICE, $debuginfo = null)
  833. {
  834. if (is_int($code)) {
  835. parent::__construct('DB Error: ' . DB::errorMessage($code), $code,
  836. $mode, $level, $debuginfo);
  837. } else {
  838. parent::__construct("DB Error: $code", DB_ERROR,
  839. $mode, $level, $debuginfo);
  840. }
  841. }
  842. /**
  843. * Workaround to both avoid the "Redefining already defined constructor"
  844. * PHP error and provide backward compatibility in case someone is calling
  845. * DB_Error() dynamically
  846. * @param $method
  847. * @param $arguments
  848. * @return bool|mixed
  849. */
  850. public function __call($method, $arguments)
  851. {
  852. if ($method == 'DB_Error') {
  853. return call_user_func_array(array($this, '__construct'), $arguments);
  854. }
  855. trigger_error(
  856. 'Call to undefined method DB_Error::' . $method . '()', E_USER_ERROR
  857. );
  858. return false;
  859. }
  860. // }}}
  861. }
  862. // }}}
  863. // {{{ class DB_result
  864. /**
  865. * This class implements a wrapper for a DB result set
  866. *
  867. * A new instance of this class will be returned by the DB implementation
  868. * after processing a query that returns data.
  869. *
  870. * @category Database
  871. * @package DB
  872. * @author Stig Bakken <ssb@php.net>
  873. * @copyright 1997-2007 The PHP Group
  874. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  875. * @version Release: 1.9.2
  876. * @link http://pear.php.net/package/DB
  877. */
  878. class DB_result
  879. {
  880. // {{{ properties
  881. /**
  882. * Should results be freed automatically when there are no more rows?
  883. * @var boolean
  884. * @see DB_common::$options
  885. */
  886. var $autofree;
  887. /**
  888. * A reference to the DB_<driver> object
  889. * @var object
  890. */
  891. var $dbh;
  892. /**
  893. * The current default fetch mode
  894. * @var integer
  895. * @see DB_common::$fetchmode
  896. */
  897. var $fetchmode;
  898. /**
  899. * The name of the class into which results should be fetched when
  900. * DB_FETCHMODE_OBJECT is in effect
  901. *
  902. * @var string
  903. * @see DB_common::$fetchmode_object_class
  904. */
  905. var $fetchmode_object_class;
  906. /**
  907. * The number of rows to fetch from a limit query
  908. * @var integer
  909. */
  910. var $limit_count = null;
  911. /**
  912. * The row to start fetching from in limit queries
  913. * @var integer
  914. */
  915. var $limit_from = null;
  916. /**
  917. * The execute parameters that created this result
  918. * @var array
  919. * @since Property available since Release 1.7.0
  920. */
  921. var $parameters;
  922. /**
  923. * The query string that created this result
  924. *
  925. * Copied here incase it changes in $dbh, which is referenced
  926. *
  927. * @var string
  928. * @since Property available since Release 1.7.0
  929. */
  930. var $query;
  931. /**
  932. * The query result resource id created by PHP
  933. * @var resource
  934. */
  935. var $result;
  936. /**
  937. * The present row being dealt with
  938. * @var integer
  939. */
  940. var $row_counter = null;
  941. /**
  942. * The prepared statement resource id created by PHP in $dbh
  943. *
  944. * This resource is only available when the result set was created using
  945. * a driver's native execute() method, not PEAR DB's emulated one.
  946. *
  947. * Copied here incase it changes in $dbh, which is referenced
  948. *
  949. * {@internal Mainly here because the InterBase/Firebird API is only
  950. * able to retrieve data from result sets if the statemnt handle is
  951. * still in scope.}}
  952. *
  953. * @var resource
  954. * @since Property available since Release 1.7.0
  955. */
  956. var $statement;
  957. // }}}
  958. // {{{ constructor
  959. /**
  960. * This constructor sets the object's properties
  961. *
  962. * @param object &$dbh the DB object reference
  963. * @param resource $result the result resource id
  964. * @param array $options an associative array with result options
  965. *
  966. * @return void
  967. */
  968. function __construct(&$dbh, $result, $options = array())
  969. {
  970. $this->autofree = $dbh->options['autofree'];
  971. $this->dbh = &$dbh;
  972. $this->fetchmode = $dbh->fetchmode;
  973. $this->fetchmode_object_class = $dbh->fetchmode_object_class;
  974. $this->parameters = $dbh->last_parameters;
  975. $this->query = $dbh->last_query;
  976. $this->result = $result;
  977. $this->statement = empty($dbh->last_stmt) ? null : $dbh->last_stmt;
  978. foreach ($options as $key => $value) {
  979. $this->setOption($key, $value);
  980. }
  981. }
  982. /**
  983. * Set options for the DB_result object
  984. *
  985. * @param string $key the option to set
  986. * @param mixed $value the value to set the option to
  987. *
  988. * @return void
  989. */
  990. function setOption($key, $value = null)
  991. {
  992. switch ($key) {
  993. case 'limit_from':
  994. $this->limit_from = $value;
  995. break;
  996. case 'limit_count':
  997. $this->limit_count = $value;
  998. }
  999. }
  1000. // }}}
  1001. // {{{ fetchRow()
  1002. /**
  1003. * Fetch a row of data and return it by reference into an array
  1004. *
  1005. * The type of array returned can be controlled either by setting this
  1006. * method's <var>$fetchmode</var> parameter or by changing the default
  1007. * fetch mode setFetchMode() before calling this method.
  1008. *
  1009. * There are two options for standardizing the information returned
  1010. * from databases, ensuring their values are consistent when changing
  1011. * DBMS's. These portability options can be turned on when creating a
  1012. * new DB object or by using setOption().
  1013. *
  1014. * + <var>DB_PORTABILITY_LOWERCASE</var>
  1015. * convert names of fields to lower case
  1016. *
  1017. * + <var>DB_PORTABILITY_RTRIM</var>
  1018. * right trim the data
  1019. *
  1020. * @param int $fetchmode the constant indicating how to format the data
  1021. * @param int $rownum the row number to fetch (index starts at 0)
  1022. *
  1023. * @return mixed an array or object containing the row's data,
  1024. * NULL when the end of the result set is reached
  1025. * or a DB_Error object on failure.
  1026. *
  1027. * @see DB_common::setOption(), DB_common::setFetchMode()
  1028. */
  1029. function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
  1030. {
  1031. if ($fetchmode === DB_FETCHMODE_DEFAULT) {
  1032. $fetchmode = $this->fetchmode;
  1033. }
  1034. if ($fetchmode === DB_FETCHMODE_OBJECT) {
  1035. $fetchmode = DB_FETCHMODE_ASSOC;
  1036. $object_class = $this->fetchmode_object_class;
  1037. }
  1038. if (is_null($rownum) && $this->limit_from !== null) {
  1039. if ($this->row_counter === null) {
  1040. $this->row_counter = $this->limit_from;
  1041. // Skip rows
  1042. if ($this->dbh->features['limit'] === false) {
  1043. $i = 0;
  1044. while ($i++ < $this->limit_from) {
  1045. $this->dbh->fetchInto($this->result, $arr, $fetchmode);
  1046. }
  1047. }
  1048. }
  1049. if ($this->row_counter >= ($this->limit_from + $this->limit_count)) {
  1050. if ($this->autofree) {
  1051. $this->free();
  1052. }
  1053. $tmp = null;
  1054. return $tmp;
  1055. }
  1056. if ($this->dbh->features['limit'] === 'emulate') {
  1057. $rownum = $this->row_counter;
  1058. }
  1059. $this->row_counter++;
  1060. }
  1061. $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
  1062. if ($res === DB_OK) {
  1063. if (isset($object_class)) {
  1064. // The default mode is specified in the
  1065. // DB_common::fetchmode_object_class property
  1066. if ($object_class == 'stdClass') {
  1067. $arr = (object)$arr;
  1068. } else {
  1069. $arr = new $object_class($arr);
  1070. }
  1071. }
  1072. return $arr;
  1073. }
  1074. if ($res == null && $this->autofree) {
  1075. $this->free();
  1076. }
  1077. return $res;
  1078. }
  1079. // }}}
  1080. // {{{ fetchInto()
  1081. /**
  1082. * Frees the resources allocated for this result set
  1083. *
  1084. * @return bool true on success. A DB_Error object on failure.
  1085. */
  1086. function free()
  1087. {
  1088. $err = $this->dbh->freeResult($this->result);
  1089. if (DB::isError($err)) {
  1090. return $err;
  1091. }
  1092. $this->result = false;
  1093. $this->statement = false;
  1094. return true;
  1095. }
  1096. // }}}
  1097. // {{{ numCols()
  1098. /**
  1099. * Fetch a row of data into an array which is passed by reference
  1100. *
  1101. * The type of array returned can be controlled either by setting this
  1102. * method's <var>$fetchmode</var> parameter or by changing the default
  1103. * fetch mode setFetchMode() before calling this method.
  1104. *
  1105. * There are two options for standardizing the information returned
  1106. * from databases, ensuring their values are consistent when changing
  1107. * DBMS's. These portability options can be turned on when creating a
  1108. * new DB object or by using setOption().
  1109. *
  1110. * + <var>DB_PORTABILITY_LOWERCASE</var>
  1111. * convert names of fields to lower case
  1112. *
  1113. * + <var>DB_PORTABILITY_RTRIM</var>
  1114. * right trim the data
  1115. *
  1116. * @param array &$arr the variable where the data should be placed
  1117. * @param int $fetchmode the constant indicating how to format the data
  1118. * @param int $rownum the row number to fetch (index starts at 0)
  1119. *
  1120. * @return mixed DB_OK if a row is processed, NULL when the end of the
  1121. * result set is reached or a DB_Error object on failure
  1122. *
  1123. * @see DB_common::setOption(), DB_common::setFetchMode()
  1124. */
  1125. function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
  1126. {
  1127. if ($fetchmode === DB_FETCHMODE_DEFAULT) {
  1128. $fetchmode = $this->fetchmode;
  1129. }
  1130. if ($fetchmode === DB_FETCHMODE_OBJECT) {
  1131. $fetchmode = DB_FETCHMODE_ASSOC;
  1132. $object_class = $this->fetchmode_object_class;
  1133. }
  1134. if (is_null($rownum) && $this->limit_from !== null) {
  1135. if ($this->row_counter === null) {
  1136. $this->row_counter = $this->limit_from;
  1137. // Skip rows
  1138. if ($this->dbh->features['limit'] === false) {
  1139. $i = 0;
  1140. while ($i++ < $this->limit_from) {
  1141. $this->dbh->fetchInto($this->result, $arr, $fetchmode);
  1142. }
  1143. }
  1144. }
  1145. if ($this->row_counter >= (
  1146. $this->limit_from + $this->limit_count)) {
  1147. if ($this->autofree) {
  1148. $this->free();
  1149. }
  1150. return null;
  1151. }
  1152. if ($this->dbh->features['limit'] === 'emulate') {
  1153. $rownum = $this->row_counter;
  1154. }
  1155. $this->row_counter++;
  1156. }
  1157. $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
  1158. if ($res === DB_OK) {
  1159. if (isset($object_class)) {
  1160. // default mode specified in the
  1161. // DB_common::fetchmode_object_class property
  1162. if ($object_class == 'stdClass') {
  1163. $arr = (object)$arr;
  1164. } else {
  1165. $arr = new $object_class($arr);
  1166. }
  1167. }
  1168. return DB_OK;
  1169. }
  1170. if ($res == null && $this->autofree) {
  1171. $this->free();
  1172. }
  1173. return $res;
  1174. }
  1175. // }}}
  1176. // {{{ numRows()
  1177. /**
  1178. * Get the the number of columns in a result set
  1179. *
  1180. * @return int the number of columns. A DB_Error object on failure.
  1181. */
  1182. function numCols()
  1183. {
  1184. return $this->dbh->numCols($this->result);
  1185. }
  1186. // }}}
  1187. // {{{ nextResult()
  1188. /**
  1189. * Get the number of rows in a result set
  1190. *
  1191. * @return int the number of rows. A DB_Error object on failure.
  1192. */
  1193. function numRows()
  1194. {
  1195. if ($this->dbh->features['numrows'] === 'emulate'
  1196. && $this->dbh->options['portability'] & DB_PORTABILITY_NUMROWS) {
  1197. if ($this->dbh->features['prepare']) {
  1198. $res = $this->dbh->query($this->query, $this->parameters);
  1199. } else {
  1200. $res = $this->dbh->query($this->query);
  1201. }
  1202. if (DB::isError($res)) {
  1203. return $res;
  1204. }
  1205. $i = 0;
  1206. while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
  1207. $i++;
  1208. }
  1209. $count = $i;
  1210. } else {
  1211. $count = $this->dbh->numRows($this->result);
  1212. }
  1213. /* fbsql is checked for here because limit queries are implemented
  1214. * using a TOP() function, which results in fbsql_num_rows still
  1215. * returning the total number of rows that would have been returned,
  1216. * rather than the real number. As a result, we'll just do the limit
  1217. * calculations for fbsql in the same way as a database with emulated
  1218. * limits. Unfortunately, we can't just do this in DB_fbsql::numRows()
  1219. * because that only gets the result resource, rather than the full
  1220. * DB_Result object. */
  1221. if (($this->dbh->features['limit'] === 'emulate'
  1222. && $this->limit_from !== null)
  1223. || $this->dbh->phptype == 'fbsql') {
  1224. $limit_count = is_null($this->limit_count) ? $count : $this->limit_count;
  1225. if ($count < $this->limit_from) {
  1226. $count = 0;
  1227. } elseif ($count < ($this->limit_from + $limit_count)) {
  1228. $count -= $this->limit_from;
  1229. } else {
  1230. $count = $limit_count;
  1231. }
  1232. }
  1233. return $count;
  1234. }
  1235. // }}}
  1236. // {{{ free()
  1237. /**
  1238. * Get the next result if a batch of queries was executed
  1239. *
  1240. * @return bool true if a new result is available or false if not
  1241. */
  1242. function nextResult()
  1243. {
  1244. return $this->dbh->nextResult($this->result);
  1245. }
  1246. // }}}
  1247. // {{{ tableInfo()
  1248. /**
  1249. * @param null $mode
  1250. * @return
  1251. * @see DB_common::tableInfo()
  1252. * @deprecated Method deprecated some time before Release 1.2
  1253. */
  1254. function tableInfo($mode = null)
  1255. {
  1256. if (is_string($mode)) {
  1257. return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
  1258. }
  1259. return $this->dbh->tableInfo($this, $mode);
  1260. }
  1261. // }}}
  1262. // {{{ getQuery()
  1263. /**
  1264. * Determine the query string that created this result
  1265. *
  1266. * @return string the query string
  1267. *
  1268. * @since Method available since Release 1.7.0
  1269. */
  1270. function getQuery()
  1271. {
  1272. return $this->query;
  1273. }
  1274. // }}}
  1275. // {{{ getRowCounter()
  1276. /**
  1277. * Tells which row number is currently being processed
  1278. *
  1279. * @return integer the current row being looked at. Starts at 1.
  1280. */
  1281. function getRowCounter()
  1282. {
  1283. return $this->row_counter;
  1284. }
  1285. // }}}
  1286. }
  1287. // }}}
  1288. // {{{ class DB_row
  1289. /**
  1290. * PEAR DB Row Object
  1291. *
  1292. * The object contains a row of data from a result set. Each column's data
  1293. * is placed in a property named for the column.
  1294. *
  1295. * @category Database
  1296. * @package DB
  1297. * @author Stig Bakken <ssb@php.net>
  1298. * @copyright 1997-2007 The PHP Group
  1299. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  1300. * @version Release: 1.9.2
  1301. * @link http://pear.php.net/package/DB
  1302. * @see DB_common::setFetchMode()
  1303. */
  1304. class DB_row
  1305. {
  1306. // {{{ constructor
  1307. /**
  1308. * The constructor places a row's data into properties of this object
  1309. *
  1310. * @param array the array containing the row's data
  1311. *
  1312. * @return void
  1313. */
  1314. function __construct(&$arr)
  1315. {
  1316. foreach ($arr as $key => $value) {
  1317. $this->$key = &$arr[$key];
  1318. }
  1319. }
  1320. // }}}
  1321. }
  1322. // }}}
  1323. /*
  1324. * Local variables:
  1325. * tab-width: 4
  1326. * c-basic-offset: 4
  1327. * End:
  1328. */