tbrehm
2011-09-26 b31bb1f27f066a2d49f5ab9ee0ca15e985efc788
server/lib/classes/db_mysql.inc.php
@@ -33,10 +33,13 @@
      var $dbName = '';      // logical database name on that server
      var $dbUser = '';      // database authorized user
      var $dbPass = '';      // user's password
      var $dbCharset = 'utf8';// Database charset
      var $dbNewLink = false; // Return a new linkID when connect is called again
      var $dbClientFlags = 0; // MySQL Client falgs
      var $linkId = 0;      // last result of mysql_connect()
      var $queryId = 0;      // last result of mysql_query()
      var $record   = array();   // last record fetched
        var $autoCommit = 1;    // Autocommit Transactions
      var $autoCommit = 1;    // Autocommit Transactions
      var $currentRow;      // current row number
      var $errorNumber = 0;   // last error number
      var $errorMessage = '';   // last error message
@@ -44,8 +47,7 @@
      var $show_error_messages = true;
      // constructor
      function db()
      {
      public function __construct() {
         
         global $conf;
         $this->dbHost = $conf['db_host'];
@@ -53,15 +55,21 @@
         $this->dbUser = $conf['db_user'];
         $this->dbPass = $conf['db_password'];
         $this->dbCharset = $conf['db_charset'];
         $this->dbNewLink = $conf['db_new_link'];
         $this->dbClientFlags = $conf['db_client_flags'];
         //$this->connect();
      }
      public function __destruct() {
         $this->closeConn();
      }
      // error handler
      function updateError($location)
      {
         global $app;
         $this->errorNumber = mysql_errno($this->linkId);
         $this->errorMessage = mysql_error($this->linkId);
         $this->errorNumber = @mysql_errno($this->linkId);
         $this->errorMessage = @mysql_error($this->linkId);
         $this->errorLocation = $location;
         if($this->errorNumber && $this->show_error_messages && method_exists($app,'log'))
         {
@@ -75,7 +83,7 @@
      {
         if($this->linkId == 0)
         {
            $this->linkId = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
            $this->linkId = @mysql_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbNewLink, $this->dbClientFlags);
            if(!$this->linkId)
            {
               $this->updateError('DB::connect()-> mysql_connect');
@@ -339,7 +347,8 @@
      
      return true;
   }
       public function closeConn()
       {
          if($this->linkId)
@@ -397,17 +406,16 @@
            if($col['autoInc'] == true) $sql .= 'auto_increment ';
            $sql.= ',';
            // key Definitionen
            if($col['option'] == 'primary') $index .= "PRIMARY KEY (".$col['name']."),";
            if($col['option'] == 'index') $index .= "INDEX (".$col['name']."),";
            if($col['option'] == 'unique') $index .= "UNIQUE (".$col['name']."),";
            if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),';
            if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),';
            if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),';
       }
       $sql .= $index;
       $sql = substr($sql,0,-1);
       $sql .= ')';
       $this->query($sql);
       return true;
       }
    }
       
       /*
       $columns = array(action =>   add | alter | drop
@@ -427,11 +435,11 @@
       $sql = "ALTER TABLE $table_name ";
       foreach($columns as $col){
            if($col['action'] == 'add') {
                $sql .= "ADD ".$col['name'].' '.$this->mapType($col['type'],$col['typeValue']).' ';
                $sql .= 'ADD '.$col['name'].' '.$this->mapType($col['type'],$col['typeValue']).' ';
            } elseif ($col['action'] == 'alter') {
                $sql .= "CHANGE ".$col['name']." ".$col['name_new'].' '.$this->mapType($col['type'],$col['typeValue']).' ';
                $sql .= 'CHANGE '.$col['name'].' '.$col['name_new'].' '.$this->mapType($col['type'],$col['typeValue']).' ';
            } elseif ($col['action'] == 'drop') {
                $sql .= "DROP ".$col['name'].' ';
                $sql .= 'DROP '.$col['name'].' ';
            }
            if($col['action'] != 'drop') {  
            if($col['defaultValue'] != '') $sql .= "DEFAULT '".$col['defaultValue']."' ";
@@ -442,10 +450,10 @@
            }
            if($col['autoInc'] == true) $sql .= 'auto_increment ';
            $sql.= ',';
            // key Definitionen
            if($col['option'] == 'primary') $index .= "PRIMARY KEY (".$col['name']."),";
            if($col['option'] == 'index') $index .= "INDEX (".$col['name']."),";
            if($col['option'] == 'unique') $index .= "UNIQUE (".$col['name']."),";
            // Index definitions
            if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),';
            if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),';
            if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),';
            }
       }
       $sql .= $index;
@@ -462,7 +470,7 @@
       return $this->query($sql);
       }
       
       // gibt Array mit Tabellennamen zurück
       // gibt Array mit Tabellennamen zur�ck
       function getTables($database_name = '') {
         
         if($database_name == '') $database_name = $this->dbName;
@@ -473,7 +481,7 @@
            return $tb_names;       
       }
       
       // gibt Feldinformationen zur Tabelle zurück
       // gibt Feldinformationen zur Tabelle zur�ck
       /*
       $columns = array(action =>   add | alter | drop
                        name =>     Spaltenname
@@ -493,7 +501,7 @@
       global $go_api,$go_info;
       // Tabellenfelder einlesen
        
        if($rows = $go_api->db->queryAllRecords("SHOW FIELDS FROM ".$table_name)){
        if($rows = $go_api->db->queryAllRecords('SHOW FIELDS FROM '.$table_name)){
        foreach($rows as $row) {
            $name = $row[0];
            $default = $row[4];