[ Index ] |
|
Code source de dotProject 2.1 RC1 |
1 <?php /* $Id: db_adodb.php,v 1.24.6.1 2007/01/31 09:36:52 ajdonnison Exp $ */ 2 /* 3 Based on Leo West's (west_leo@yahooREMOVEME.com): 4 lib.DB 5 Database abstract layer 6 ----------------------- 7 ADODB VERSION 8 ----------------------- 9 A generic database layer providing a set of low to middle level functions 10 originally written for WEBO project, see webo source for "real life" usages 11 */ 12 if (!defined('DP_BASE_DIR')) { 13 die('You should not access this file directly'); 14 } 15 16 require_once ( DP_BASE_DIR."/lib/adodb/adodb.inc.php" ); 17 18 $db = NewADOConnection($dPconfig['dbtype']); 19 20 function db_connect( $host='localhost', $dbname, $user='root', $passwd='', $persist=false ) { 21 global $db, $ADODB_FETCH_MODE; 22 23 if ($persist) { 24 $db->PConnect($host, $user, $passwd, $dbname) 25 or die( 'FATAL ERROR: Connection to database server failed' ); 26 } else { 27 $db->Connect($host, $user, $passwd, $dbname) 28 or die( 'FATAL ERROR: Connection to database server failed' ); 29 } 30 31 $ADODB_FETCH_MODE=ADODB_FETCH_BOTH; 32 } 33 34 function db_error() { 35 global $db; 36 if (! is_object($db)) 37 dprint(__FILE__,__LINE__, 0, "Database object does not exist"); 38 return $db->ErrorMsg(); 39 } 40 41 function db_errno() { 42 global $db; 43 if (! is_object($db)) 44 dprint(__FILE__,__LINE__, 0, "Database object does not exist"); 45 return $db->ErrorNo(); 46 } 47 48 function db_insert_id() { 49 global $db; 50 if (! is_object($db)) 51 dprint(__FILE__,__LINE__, 0, "Database object does not exist"); 52 return $db->Insert_ID(); 53 } 54 55 function db_exec( $sql ) { 56 global $db; 57 58 if (! is_object($db)) 59 dprint(__FILE__,__LINE__, 0, "Database object does not exist"); 60 $qid = $db->Execute( $sql ); 61 dprint(__FILE__, __LINE__, 10, $sql); 62 if ($msg = db_error()) 63 { 64 global $AppUI; 65 dprint(__FILE__, __LINE__, 0, "Error executing: <pre>$sql</pre>"); 66 // Useless statement, but it is being executed only on error, 67 // and it stops infinite loop. 68 $db->Execute( $sql ); 69 if (!db_error()) 70 echo '<script language="JavaScript"> location.reload(); </script>'; 71 } 72 if ( ! $qid && preg_match('/^\<select\>/i', $sql) ) 73 dprint(__FILE__, __LINE__, 0, $sql); 74 return $qid; 75 } 76 77 function db_free_result($cur ) { 78 // TODO 79 // mysql_free_result( $cur ); 80 // Maybe it's done my Adodb 81 if (! is_object($cur)) 82 dprint(__FILE__, __LINE__, 0, "Invalid object passed to db_free_result"); 83 $cur->Close(); 84 } 85 86 function db_num_rows( $qid ) { 87 if (! is_object($qid)) 88 dprint(__FILE__, __LINE__, 0, "Invalid object passed to db_num_rows"); 89 return $qid->RecordCount(); 90 //return $db->Affected_Rows(); 91 } 92 93 function db_fetch_row( &$qid ) { 94 if (! is_object($qid)) 95 dprint(__FILE__, __LINE__, 0, "Invalid object passed to db_fetch_row"); 96 return $qid->FetchRow(); 97 } 98 99 function db_fetch_assoc( &$qid ) { 100 if (! is_object($qid)) 101 dprint(__FILE__, __LINE__, 0, "Invalid object passed to db_fetch_assoc"); 102 return $qid->FetchRow(); 103 } 104 105 function db_fetch_array( &$qid ) { 106 if (! is_object($qid)) 107 dprint(__FILE__, __LINE__, 0, "Invalid object passed to db_fetch_array"); 108 $result = $qid->FetchRow(); 109 // Ensure there are numerics in the result. 110 if ($result && ! isset($result[0])) { 111 $ak = array_keys($result); 112 foreach ($ak as $k => $v) { 113 $result[$k] = $result[$v]; 114 } 115 } 116 return $result; 117 } 118 119 function db_fetch_object( $qid ) { 120 if (! is_object($qid)) 121 dprint(__FILE__, __LINE__, 0, "Invalid object passed to db_fetch_object"); 122 return $qid->FetchNextObject(false); 123 } 124 125 function db_escape( $str ) { 126 global $db; 127 return substr($db->qstr( $str ), 1, -1); 128 } 129 130 function db_version() { 131 return "ADODB"; 132 } 133 134 function db_unix2dateTime( $time ) { 135 global $db; 136 return $db->DBDate($time); 137 } 138 139 function db_dateTime2unix( $time ) { 140 global $db; 141 142 return $db->UnixDate($time); 143 144 // TODO - check if it's used anywhere... 145 // if ($time == '0000-00-00 00:00:00') { 146 // return -1; 147 // } 148 } 149 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 18 19:46:52 2007 | par Balluche grâce à PHPXref 0.7 |