[ PHPXref.com ] [ Generated: Sun Jul 20 19:34:26 2008 ] [ phpComasy 0.7.8 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/classes/ -> class.mysql.php (source)

   1  <?php
   2  /********************************************************************************

   3  * phpComasy, Content Management System                                            *

   4  * http://www.phpcomasy.org                                                      *

   5  *                                                                               *

   6  * Copyright (c) 2005 Emanuel Zuber (www.noreality.ch)                           *

   7  *                                                                               *

   8  * Released under the GNU General Public License                                 *

   9  ********************************************************************************/
  10  
  11  /* Includes */

  12  require_once("config.php");
  13  
  14  class mysql {
  15      var $connection;
  16      var $log_path;
  17      
  18      var $server;
  19      var $username;
  20      var $password;
  21      var $database;
  22      
  23  	function mysql() {
  24          $this->log_path = "./log/error.log";
  25          $this->server = GLOBAL_DATABASE_SERVER;
  26          $this->database = GLOBAL_DATABASE_DATABASE;
  27          $this->username = GLOBAL_DATABASE_USERNAME;
  28          $this->password = GLOBAL_DATABASE_PASSWORD;
  29          
  30          $this->connect();
  31      }
  32      
  33  	function connect() {
  34          $this->connection = mysql_connect($this->server, $this->username, $this->password);
  35          
  36          if (!$this->connection) {
  37             $msg = "Not connected to mysql server: ".mysql_error()."\n";
  38             $this->make_log_entry($msg);
  39             echo $msg;
  40          }
  41          if (!mysql_select_db($this->database)) {
  42             echo "No database selected \"".$this->database."\": " . mysql_error()."\n";
  43          }
  44      }
  45      
  46  	function query($query) {
  47          $result = mysql_query($query);
  48          if($result == false) {
  49              $this->make_log_entry("mysql error: query wasn't successful: ".mysql_error()."\n");
  50              $this->make_log_entry("previous query: ".$query."\n");
  51              return false;
  52          }
  53          return $result;
  54      }
  55      
  56  	function make_log_entry($msg) {
  57          if($this->log_path !== "") {
  58              if($msg[strlen($msg)-1] !== "\n") {
  59                  $msg .= "\n";
  60              }
  61              error_log(date("Y-d-m H:i:s")." MYSQL ".$msg, 3, $this->log_path);
  62          }
  63      }
  64  }
  65  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]