DB.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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 (empty($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. */