DB_Mysql Class Reference

Inherits database.

List of all members.

Public Member Functions

  • db_input ($strString)
    Alias retro-compatibilité.

Protected Member Functions

Protected Attributes


Detailed Description

Definition at line 14 of file DB_Mysql.php.


Member Function Documentation

DB_Mysql::begin_transaction (  )  [protected]

Begin a transaction.

Definition at line 165 of file DB_Mysql.php.

00166         {
00167                 @mysql_query("SET AUTOCOMMIT=0", $this->resConnection);
00168                 @mysql_query("BEGIN", $this->resConnection);
00169         }

DB_Mysql::commit_transaction (  )  [protected]

Commit a transaction.

Definition at line 175 of file DB_Mysql.php.

00176         {
00177                 @mysql_query("COMMIT", $this->resConnection);
00178                 @mysql_query("SET AUTOCOMMIT=1", $this->resConnection);
00179         }

DB_Mysql::connect (  )  [protected]

Connect to database server and select database.

Definition at line 37 of file DB_Mysql.php.

00037                                {
00038     $strHost = parent::HOST;
00039 
00040     if (parent::PORT) $strHost .= ':' . parent::PORT;
00041 
00042     if (parent::PCONNECT =='true')$this->resConnection = @mysql_pconnect($strHost, parent::USER, parent::PASS);
00043     else $this->resConnection = @mysql_connect($strHost, parent::USER, parent::PASS);
00044 
00045     if (is_resource($this->resConnection))
00046     {
00047             @mysql_query("SET sql_mode=''", $this->resConnection);
00048             @mysql_query("SET NAMES " . parent::CHARSET, $this->resConnection);
00049             @mysql_select_db(parent::DB, $this->resConnection);
00050     }
00051   }

DB_Mysql::db_input ( strString  ) 

Alias retro-compatibilité.

Definition at line 194 of file DB_Mysql.php.

00195         {
00196                 return  mysql_real_escape_string($strString, $this->resConnection) ;
00197         }

DB_Mysql::disconnect (  )  [protected]

Disconnect from database.

Definition at line 57 of file DB_Mysql.php.

00057                                   {
00058     @mysql_close($this->resConnection);
00059   }

DB_Mysql::get_error (  )  [protected]

Return the last error message.

Returns:
string

Definition at line 66 of file DB_Mysql.php.

00066                                  {
00067     if (is_resource($this->resConnection)) return mysql_error($this->resConnection);
00068 
00069     return mysql_error();
00070   }

DB_Mysql::list_fields ( strTable  )  [protected]

Return a standardized array with field information.

Standardized format:

  • name: field name (e.g. my_field)
  • type: field type (e.g. "int" or "number")
  • length: field length (e.g. 20)
  • precision: precision of a float number (e.g. 5)
  • null: NULL or NOT NULL
  • default: default value (e.g. "default_value")
  • attributes: attributes (e.g. "unsigned")
  • index: PRIMARY, UNIQUE or INDEX
  • extra: extra information (e.g. auto_increment)
    Parameters:
    string 
    Returns:
    string
    Todo:
    Support all kind of keys (e.g. FULLTEXT or FOREIGN).

Definition at line 90 of file DB_Mysql.php.

00091         {
00092                 $arrReturn = array();
00093                 $arrFields_query = mysql_query(sprintf($this->strListFields, $strTable), $this->resConnection) ; /*->fetchAllAssoc() ;*/
00094 
00095                 while ($arrF = mysql_fetch_assoc($arrFields_query))
00096                   $arrFields[]=$arrF;
00097 
00098 
00099                 foreach ($arrFields as $k=>$v)
00100                 {
00101                         $arrChunks = preg_split('/(\([^\)]+\))/', $v['Type'], -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
00102 // print_r($arrChunks);
00103                         $arrReturn[$k]['name'] = $v['Field'];
00104                         $arrReturn[$k]['type'] = $arrChunks[0];
00105 
00106                         if (isset($arrChunks[1]) &&  strlen($arrChunks[1]))
00107                         {
00108                                 $arrChunks[1] = str_replace(array('(', ')'), array('', ''), $arrChunks[1]);
00109                                 $arrSubChunks = explode(',', $arrChunks[1]);
00110 
00111                                 $arrReturn[$k]['length'] = trim($arrSubChunks[0]);
00112 
00113                                 if (isset($arrSubChunks[1]) && strlen($arrSubChunks[1]))
00114                                 {
00115                                         $arrReturn[$k]['precision'] = trim($arrSubChunks[1]);
00116                                 }
00117                         }
00118 
00119                         if (isset($arrSubChunks[2]) && strlen($arrChunks[2]))
00120                         {
00121                                 $arrReturn[$k]['attributes'] = trim($arrChunks[2]);
00122                         }
00123 
00124                         if (strlen($v['Key']))
00125                         {
00126                                 switch ($v['Key'])
00127                                 {
00128                                         case 'PRI':
00129                                                 $arrReturn[$k]['index'] = 'PRIMARY';
00130                                                 break;
00131 
00132                                         case 'UNI':
00133                                                 $arrReturn[$k]['index'] = 'UNIQUE';
00134                                                 break;
00135 
00136                                         default:
00137                                                 $arrReturn[$k]['index'] = 'KEY';
00138                                                 break;
00139                                 }
00140                         }
00141 
00142                         $arrReturn[$k]['null'] = ($v['Null'] == 'YES') ? 'NULL' : 'NOT NULL';
00143                         $arrReturn[$k]['default'] = $v['Default'];
00144                         $arrReturn[$k]['extra'] = $v['Extra'];
00145                 }
00146 
00147                 return $arrReturn;
00148         }

DB_Mysql::rollback_transaction (  )  [protected]

Rollback a transaction.

Definition at line 185 of file DB_Mysql.php.

00186         {
00187                 @mysql_query("ROLLBACK", $this->resConnection);
00188                 @mysql_query("SET AUTOCOMMIT=1", $this->resConnection);
00189         }

DB_Mysql::set_database ( strDatabase  )  [protected]

Change the current database.

Parameters:
string 
Returns:
boolean

Definition at line 156 of file DB_Mysql.php.

00157         {
00158                 return @mysql_select_db($strDatabase, $this->resConnection);
00159         }


Member Data Documentation

DB_Mysql::$resConnection [protected]

Definition at line 32 of file DB_Mysql.php.

DB_Mysql::$strListFields = "SHOW COLUMNS FROM `%s`" [protected]

Definition at line 26 of file DB_Mysql.php.

DB_Mysql::$strListTables = "SHOW TABLES FROM `%s`" [protected]

Definition at line 20 of file DB_Mysql.php.


The documentation for this class was generated from the following file: