PHP Classes

File: lib_dbd_mysql.class

Recommend this page to a friend!
  Classes of Thomas Werner   DBI   lib_dbd_mysql.class   Download  
File: lib_dbd_mysql.class
Role: ???
Content type: text/plain
Description: MySQL Database Driver
Class: DBI
Author: By
Last change:
Date: 24 years ago
Size: 3,816 bytes
 

Contents

Class file image Download
<?php class DBD_mysql { /******************************************************************************* Description : PHP Database Driver for MySQL Author : Thomas Werner Author Email : [email protected] Created : 20000801 Last Modified : 20000801 Info : n/a *******************************************************************************/ var $DBI; var $dbh; function error($str) { echo "$str<BR>\n"; exit; } // End Error function connect($dbname, $dbhost = '', $dbuser = '', $dbpwd = ''){ $conn = @mysql_connect($dbhost, $dbuser, $dbpwd); if(!$conn) { $this->error("DBD::mysql Error: Could not connect to the database."); return; } if(!mysql_select_db($dbname)) { $this->error("DBD::mysql Error: Could not select the database."); return; } $this->dbh = $conn; return($this); } // End Connect function pconnect($dbname, $dbhost = '', $dbuser = '', $dbpwd = ''){ $conn = @mysql_pconnect($dbhost, $dbuser, $dbpwd); if(!$conn) { $this->error("DBD::mysql Error: Could not connect to the database."); return; } if(!mysql_select_db($dbname)) { $this->error("DBD::mysql Error: Could not select the database."); return; } $this->dbh = $conn; return($this); } // End Connect function disconnect( ) { mysql_close($this->dbh); $this->dbh = undef; return(1); } // End Disconnect function prepare($query) { if(!$this->dbh){ return; } $sth = new STH_mysql; $sth->DBH($this); $sth->prepare($query); return($sth); } // End Prepare } // End DBD Class class STH_mysql { var $query; var $DBH; var $dbh; var $result; function error($str) { echo "$str<BR>\n"; exit; } // End Error function DBH($dbh) { $this->DBH = $dbh; $this->dbh = $dbh->dbh; return( $dbh ); } function prepare($query) { if(!$this->dbh){ return; } $this->query = $query; return($query); } function execute() { if(!$this->dbh ){ return; } // DEBUG: // echo "Running query $this->query<br>\n"; $this->result = mysql_query($this->query, $this->dbh); if(!$this->result) { // DEBUG: //$this->error("STH Execute failed: ".mysql_error( $this->dbh )); return; } return(1); } // End Execute function insert_id() { return(mysql_insert_id($this->dbh)); } // End Insert_ID function finish() { if(!$this->result){ return; } mysql_free_result($this->result); $this->result = undef; return(1); } // End Finish function rows() { if(!$this->dbh){ return; } return mysql_num_rows($this->result); } // End Rows function fetchrow_array() { if(!$this->result){ //echo "STH Error: Calling fetchrow on null result.<br>\n"; return; } return(mysql_fetch_row($this->result)); } // End Fetchrow_array function fetchrow_hash() { if(!$this->result){ //echo "STH Error: Calling fetchrow on null result.<br>\n"; return; } return( mysql_fetch_array($this->result)); } // End Fetchrow_hash function fetchrow_hashref() { if(!$this->result){ //echo "STH Error: Calling fetchrow on null result.<br>\n"; return; } return( mysql_fetch_object($this->result)); } // End Fetchrow_hash } // End Class STH $GLOBALS[lib_dbd_mysql_read] = 1; ?>