Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#216 Login/register    Go to Bottom
Go to Top

Source for file dpdb_mdb2.php

Documentation is available at dpdb_mdb2.php

  1. <?php
  2. /**
  3.  * MDB2 database functions
  4.  *
  5.  * A very simple layer over MDB2 functions, providing the same interface as
  6.  * dpdb_mysql.php. MDB2 is a database abstraction layer, pary of PHP's PEAR
  7.  * library, and provides interfaces for a number of databases.
  8.  * Either this file or dpdb_mysql.php is included, based on settings in
  9.  * dpuniverse-ini.php.
  10.  *
  11.  * DutchPIPE version 0.4; PHP version 5
  12.  *
  13.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  14.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  15.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  16.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  17.  *
  18.  * @package    DutchPIPE
  19.  * @subpackage lib
  20.  * @author     Lennert Stock <ls@dutchpipe.org>
  21.  * @copyright  2006, 2007 Lennert Stock
  22.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  23.  * @version    Subversion: $Id: dpdb_mdb2.php 287 2007-08-21 18:47:19Z ls $
  24.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  25.  * @see        dpuniverse-ini.php, dpdb_mysql.php
  26.  * @since      DutchPIPE 0.4.0
  27.  */
  28.  
  29. /**
  30.  * PEAR:MDB2.php must be installed
  31.  */
  32. require_once(DPUNIVERSE_MDB2_PEAR_PATH 'MDB2.php');
  33.  
  34. /**
  35.  * Connects to the database server and sets it the current database
  36.  *
  37.  * Prints an error message to the server output in case of an error
  38.  *
  39.  * @return     boolean   MDB2 connection object on success, FALSE on failure
  40.  * @see        DPUNIVERSE_MDB2_DSN, DPUNIVERSE_MDB2_CONNECT_OPTIONS,
  41.  *              MDB2::singleton, dp_db_query, dp_db_exec, dp_db_fetch_one,
  42.  *              dp_db_fetch_row, dp_db_quote, dp_db_num_rows, dp_db_next_id,
  43.  *              dp_db_free
  44.  * @ignore
  45.  */
  46. function &dp_db_connect()
  47. {
  48.     global $DPUNIVERSE_MDB2_DSN$DPUNIVERSE_MDB2_CONNECT_OPTIONS;
  49.  
  50.     $mdb2 =MDB2::singleton($DPUNIVERSE_MDB2_DSN,
  51.         $DPUNIVERSE_MDB2_CONNECT_OPTIONS);
  52.     if (PEAR::isError($mdb2)) {
  53.         echo $mdb2->getMessage("\n";
  54.         $mdb2 FALSE;
  55.     }
  56.  
  57.     return $mdb2;
  58. }
  59.  
  60. /**
  61.  * Sends a database query of type SELECT, SHOW, EXPLAIN, DESCRIBE, ...
  62.  *
  63.  * Prints an error message to the server output in case of an error
  64.  *
  65.  * @param      string    $sql        SQL statement
  66.  * @return     mixed     MB2 result object or FALSE for failure
  67.  * @see        MDB2::query, dp_db_connect, dp_db_exec, dp_db_fetch_one,
  68.  *              dp_db_fetch_row, dp_db_quote, dp_db_num_rows, dp_db_free
  69.  * @ignore
  70.  */
  71. function dp_db_query($sql)
  72. {
  73.     global $DPUNIVERSE_MDB2_DSN$DPUNIVERSE_MDB2_CONNECT_OPTIONS;
  74.  
  75.     if (!($mdb2 &dp_db_connect())) {
  76.         return FALSE;
  77.     }
  78.  
  79.     $result =$mdb2->query($sql);
  80.     if (PEAR::isError($result)) {
  81.         echo $result->getMessage("\n";
  82.         return FALSE;
  83.     }
  84.  
  85.     return $result;
  86. }
  87.  
  88. /**
  89.  * Sends a database query of type DELETE, INSERT, REPLACE, UPDATE, ...
  90.  *
  91.  * Prints an error message to the server output in case of an error
  92.  *
  93.  * @param      string    $sql        SQL statement
  94.  * @return     mixed     number of affected rows or FALSE for failure
  95.  * @see        MDB2::exec, dp_db_connect, dp_db_query, dp_db_quote,
  96.  *              dp_db_next_id
  97.  * @ignore
  98.  */
  99. function dp_db_exec($sql)
  100. {
  101.     global $DPUNIVERSE_MDB2_DSN$DPUNIVERSE_MDB2_CONNECT_OPTIONS;
  102.  
  103.     if (!($mdb2 &dp_db_connect())) {
  104.         return FALSE;
  105.     }
  106.  
  107.     $affected =$mdb2->exec($sql);
  108.     if (PEAR::isError($affected)) {
  109.         echo $affected->getMessage("\n";
  110.         return FALSE;
  111.     }
  112.  
  113.     return $affected;
  114. }
  115.  
  116. /**
  117.  * Gets result data
  118.  *
  119.  * Prints an error message to the server output in case of an error
  120.  *
  121.  * @param      resource  $result     MB2 result object from dp_db_query()
  122.  * @param      int       $row        row number from result, starts at 0
  123.  * @param      int       $field      optional field name or offset, 0 by default
  124.  * @return     mixed     string with contents of one cell, or FALSE on failure
  125.  * @see        MDB2::fetchOne, dp_db_connect, dp_db_query, dp_db_fetch_row,
  126.  *              dp_db_quote, dp_db_num_rows, dp_db_free
  127.  * @ignore
  128.  */
  129. function dp_db_fetch_one($result$row$field 0)
  130. {
  131.     $one =$result->fetchOne($field$row);
  132.     if (PEAR::isError($one)) {
  133.         echo $one->getMessage("\n";
  134.         return FALSE;
  135.     }
  136.  
  137.     return $one;
  138. }
  139.  
  140. /**
  141.  * Gets a result row as an enumerated array
  142.  *
  143.  * @param      resource  $result     MB2 result object from dp_db_query()
  144.  * @return     mixed     numerical array of strings with row data, FALSE if
  145.  *                        there are no more rows
  146.  * @see        MDB2::fetchRow, dp_db_connect, dp_db_query, dp_db_fetch_one,
  147.  *              dp_db_quote, dp_db_num_rows, dp_db_free
  148.  * @ignore
  149.  */
  150. function &dp_db_fetch_row($result)
  151. {
  152.     $row =$result->fetchRow();
  153.     if (PEAR::isError($row)) {
  154.         echo $row->getMessage("\n";
  155.         return FALSE;
  156.     }
  157.  
  158.     return $row;
  159. }
  160.  
  161. /**
  162.  * Escapes special characters in a string for use in a SQL statement
  163.  *
  164.  * Escapes the value given in the first argument. All other arguments are only
  165.  * used by this MDB2 function and ignored by the MySQL equivalent.
  166.  *
  167.  * @param      string    $val           string that is to be escaped
  168.  * @param      string    $type           optional type to convert to
  169.  * @param      boolean   $quote           quote and escape value?
  170.  * @param      boolean   $escWildcards  escape wildcards?
  171.  * @return     mixed     escaped string, or FALSE on error
  172.  * @see        MDB2::quote, dp_db_query, dp_db_exec
  173.  * @ignore
  174.  */
  175. function dp_db_quote($val$type NULL$quote TRUE$escWildcards FALSE)
  176. {
  177.     global $DPUNIVERSE_MDB2_DSN$DPUNIVERSE_MDB2_CONNECT_OPTIONS;
  178.  
  179.     if (!($mdb2 &dp_db_connect())) {
  180.         return FALSE;
  181.     }
  182.  
  183.     return $mdb2->quote($val$type$quote$escWildcards);
  184. }
  185.  
  186. /**
  187.  * Gets number of rows in result
  188.  *
  189.  * Prints an error message to the server output in case of an error
  190.  *
  191.  * @param      resource  $result     MB2 result object from dp_db_query()
  192.  * @return     mixed     number of rows in a result set, or FALSE on failure
  193.  * @see        MDB2::numRows, dp_db_query
  194.  * @ignore
  195.  */
  196. function dp_db_num_rows($result)
  197. {
  198.     $num_rows =$result->numRows();
  199.     if (PEAR::isError($num_rows)) {
  200.         echo $num_rows->getMessage("\n";
  201.         return FALSE;
  202.     }
  203.  
  204.     return $num_rows;
  205. }
  206.  
  207. /**
  208.  * Gets the next primary ID for an INSERT
  209.  *
  210.  * Prints an error message to the server output in case of an error
  211.  *
  212.  * @param      string    $table      table name
  213.  * @param      string    $idColumn   field name
  214.  * @return     mixed     integer with next id, or FALSE for failure
  215.  * @see        dp_db_exec
  216.  * @ignore
  217.  */
  218. function dp_db_next_id($table$idColumn)
  219. {
  220.     global $DPUNIVERSE_MDB2_DSN$DPUNIVERSE_MDB2_CONNECT_OPTIONS;
  221.  
  222.     if (!($mdb2 &dp_db_connect())) {
  223.         return FALSE;
  224.     }
  225.  
  226.     $next_id =$mdb2->nextID($table);
  227.     if (PEAR::isError($next_id)) {
  228.         echo $next_id->getMessage("\n";
  229.         return FALSE;
  230.     }
  231.  
  232.     return $next_id;
  233. }
  234.  
  235. /**
  236.  * Frees result memory
  237.  *
  238.  * @param      resource  $result     MB2 result object from dp_db_query()
  239.  * @return     boolean   TRUE on success or FALSE on failure
  240.  * @see        MDB2::free, dp_db_query, dp_db_fetch_one, dp_db_fetch_row
  241.  * @ignore
  242.  */
  243. function dp_db_free($result)
  244. {
  245.     return is_object($result&& $result->free();
  246. }
  247. ?>

Documentation generated on Mon, 03 Sep 2007 22:19:08 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#216
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.