[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/database/pdb/drivers/pdbdriverbase.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/database/pdb/drivers/pdbmysqlrecordset.class.php" ); 5 /** 6 * \ingroup PDb 7 * 8 * MySQL driver for PDb 9 */ 10 class PDbMySQLDriver extends PDbDriverBase 11 { 12 13 var $_res; 14 var $_dbname; 15 var $_charset; 16 17 /** 18 * Constructor of the driver. Doesn't do much. 19 */ 20 function PDbMySQLDriver() 21 { 22 $this->PDbDriverBase(); 23 24 // the driver name 25 $this->_type = 'mysql'; 26 27 // character set, 'default' until one is explicitely set 28 $this->_charset = 'default'; 29 } 30 31 /** 32 * @see PDbDriverBase::Execute() 33 */ 34 function Execute( $query, $page = -1, $itemsPerPage = 15 ) 35 { 36 global $__pdb_num_queries; 37 38 if( $page > -1 ) { 39 $start = (($page - 1) * $itemsPerPage); 40 $limits = " LIMIT $start, $itemsPerPage"; 41 $query .= " $limits"; 42 } 43 44 // execute the query and see whether it was incorrect 45 $this->_debugQuery( $query ); 46 47 // as per the comments in http://www.php.net/manual/en/function.mysql-select-db.php, looks like 48 // in situations where we've got more than one table in the same server using the same 49 // connection parameters, we either need to select the database *everytime* we want to make 50 // a query or use slightly different connection paramters. I am not sure if this has any 51 // performance hit, though. 52 mysql_select_db( $this->_dbname, $this->_res ); 53 54 // increment the number of queries executed so far, regardless of what they were 55 $__pdb_num_queries++; 56 57 $result = mysql_query( $query, $this->_res ); 58 if( !$result ) { 59 if( $this->_debug ) { 60 print("<hr/>ERROR MESSAGE: ".$this->ErrorMsg()."<br/>"); 61 } 62 return false; 63 } 64 65 // if not, create a RecordSet based on it 66 $rs = new PdbMySQLRecordSet( $result ); 67 return( $rs ); 68 } 69 70 /** 71 * @see PDbDriverBase::Connect() 72 */ 73 function Connect( $host, $username, $password, $dbname = null, $dbcharset = null ) 74 { 75 PDbDriverBase::Connect( $host, $username, $password, $dbname ); 76 77 // try to connect and quit if unsuccessful 78 $this->_res = mysql_connect( $host, $username, $password ); 79 if( !$this->_res ) 80 return false; 81 82 // set the right character encoding for mysql 4.1+ client, connection and collation 83 if( !empty( $dbcharset ) && $dbcharset != "default" ) { 84 mysql_query( "SET NAMES ".$dbcharset, $this->_res ); 85 $this->_charset = $dbcharset; 86 } 87 88 // continue otherwise and try to select our db 89 if( $dbname ) 90 return( mysql_select_db( $dbname, $this->_res )); 91 else 92 return( true ); 93 } 94 95 /** 96 * @see PDbDriverBase::PConnect() 97 */ 98 function PConnect( $host, $username, $password, $dbname = null, $dbcharset = null ) 99 { 100 PDbDriverBase::Connect( $host, $username, $password, $dbname ); 101 102 // try to connect and quit if unsuccessful 103 $this->_res = mysql_pconnect( $host, $username, $password ); 104 if( !$this->_res ) 105 return false; 106 107 // set the right character encoding for mysql 4.1+ client, connection and collation 108 if( !empty( $dbcharset ) && $dbcharset != "default" ) { 109 mysql_query( "SET NAMES ".$dbcharset, $this->_res ); 110 $this->_charset = $dbcharset; 111 } 112 113 // continue otherwise and try to select our db 114 if( $dbname ) 115 return( mysql_select_db( $dbname, $this->_res )); 116 else 117 return( true ); 118 } 119 120 /** 121 * @see PDbDriverBase::Close() 122 */ 123 function Close() 124 { 125 return( mysql_close( $this->_res )); 126 } 127 128 /** 129 * @see PDbDriverBase::ErrorMsg() 130 */ 131 function ErrorMsg() 132 { 133 return( mysql_error( $this->_res )); 134 } 135 136 /** 137 * @see PDbDriverBase::Insert_ID() 138 */ 139 function Insert_ID() 140 { 141 return( mysql_insert_id( $this->_res )); 142 } 143 144 /** 145 * @see PDbDriverBase::Affected_Rows() 146 */ 147 function Affected_Rows() 148 { 149 return( mysql_affected_rows( $this->_res )); 150 } 151 152 /** 153 * @see PDbDriverBase::getDriverDataDictionary() 154 */ 155 function getDriverDataDictionary() 156 { 157 return( PDbDriverBase::getDriverDataDictionary( 'mysql' )); 158 } 159 160 /** 161 * Returns true if the current database supports FULLTEXT searches. This is currently 162 * configured in the database configuration file, config/config.properties.php: 163 * 164 * <pre> 165 * $config['db_options'] = Array( "enable_mysql_fulltext_search" => false ); 166 * </pre> 167 * 168 * @return true if FULLTEXT is supported 169 */ 170 function isFullTextSupported() 171 { 172 isset( $this->_opts["enable_mysql_fulltext_search"] ) ? $enableFullText = $this->_opts["enable_mysql_fulltext_search"] : $enableFullText = false; 173 174 return( $enableFullText ); 175 } 176 177 /** 178 * Return the name of the character set currently being used 179 * 180 * @see PDbDriverBase::getDbCharacterSet() 181 */ 182 function getDbCharacterSet() 183 { 184 return( $this->_charset ); 185 } 186 } 187 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |