Filter:   InfoImg
download db_my.php
Language: PHP
LOC: 136
Project Info
Virtual Photo Album(vphotoalb)
Server: SourceForge
Type: cvs
...alb\vphotoalb\html\include\
   .htaccess
   antispam.php
   constants.php
   db.php
   db_my.php
   db_pg.php
   db_schema.php
   faq_strings.php
   form.php
   functions.php
   globals.php
   html.php
   html_verifier.php
   ImageProcessing.php
   input.php
   mime.php
   originals.php
   PictureFinder.php
   queries.php
   read_exif_data.php
   read_tiff_data.php
   SearchParameters.php
   security.php
   strings.en.php
   strings.fr.php
   strings.php
   tables.php

<?php
/* Database class declarations for MySQL.
 *
 * Written by: Chris Studholme
 * Copyright:  GPL (http://www.fsf.org/copyleft/gpl.html)
 * $Id: db_my.php,v 1.5 2002/08/16 22:48:55 cstudhol Exp $
 */


class mysql_resultset extends db_resultset {

  var $handle=false;
  var $connection=false;

  // constructor: new resultset
  function mysql_resultset($handle,$connection) {
    $this->handle = $handle;
    $this->connection = $connection;
  }

  // number of rows in result set
  function num_rows() {
    return mysql_num_rows($this->handle);
  }

  // number of fields in result set
  function num_fields() {
    return mysql_num_fields($this->handle);
  }

  // last error message related to this resultset
  function last_error() {
    return mysql_error($this->connection);
  }

  // close resultset and free memory
  function close() {
    mysql_free_result($this->handle);
    $this->handle=false;
  }

  // return field name
  function field_name($index) {
    return mysql_field_name($this->handle,$index);
  }

  // fetch a specific row and column from the result set
  function result($row,$field) {
    return mysql_result($this->handle,$row,$field);
  }

  // reset to the first row in the result set
  function reset() {
    mysql_data_seek($this->handle,0);
  }
  
  // return the next row as an array or false if there are no more rows
  function fetch_array($result_type=false) {
    switch ($result_type) {
    case $this->NUM:   $rt = MYSQL_NUM;   break;
    case $this->ASSOC: $rt = MYSQL_ASSOC; break;
    default:           $rt = MYSQL_BOTH;  break;
    }
    return mysql_fetch_array($this->handle,$rt);
  }
}


class mysql_connection extends db_connection {

  var $handle=false;
  var $db_name=false;

  // constructor: create connection to database
  function mysql_connection($host,$login,$password,$dbname,$persistent=false) {
    if ($dbname) {
      if ($persistent)
 	$this->handle = mysql_pconnect($host,$login,$password);
      else
	$this->handle = mysql_connect($host,$login,$password);
      if (!$this->handle)
	return;
      if (!mysql_select_db($dbname,$this->handle)) {
	mysql_close($this->handle);
	$this->handle=false;
      }
      else {
	$this->db_name = $dbname;
      }
    }
  }

  // create connection to database
  function connect($host,$login,$password) {
    $this->handle = mysql_connect($host,$login,$password);
    return $this->handle;
  }

  // create persistent connection
  function pconnect($host,$login,$password) {
    $this->handle = mysql_pconnect($host,$login,$password);
    return $this->handle;
  }

  // close the connection
  function close() {
    mysql_close($this->handle);
  }

  // get last error message from connection
  function last_error() {
    return mysql_error($this->handle);
  }

  // return database name
  function name() {
    return $this->db_name;
  }

  // execute a database query
  // returns a db_result_set object
  function query($query,$return_error=false) {
    if (is_array($this->queries)) {
      $a["query"] = $query;
      list($usec,$sec)=explode(" ",microtime()); 
      $start = $sec + ((float)$usec);
    }
    $result = mysql_query($this->handle,$query);
    if (is_array($this->queries)) {
      list($usec,$sec)=explode(" ",microtime()); 
      $a["time"] = $sec + ((float)$usec) - $start;
      $this->queries[] = $a;
    }
    if ($result)
      return new mysql_resultset($result,$this->handle);
    // an error occured (call error_function if set and requested)
    if ($this->error_function&&!$return_error) {
      $func=$this->error_function;
      $func($this,$query);
    }
    return false;
  }


  /**** transactions ****/

  function transaction_begin() {
    return true;
  }

  function transaction_commit() {
    return true;
  }

  function transaction_rollback() {
    return false;
  }


  /**** SQL feature set ****/

  // returns an associative array of features
  function sql_features() {
    return array_merge(parent::sql_features(),
		       array("except"=>false,           // supports EXCEPT 
			     "subselect_from"=>false,   // supports subquery in FROM
			     "subselect_select"=>false, // supports subquery in SELECT
			     "subselect_where"=>false,  // supports subquery in WHERE
			     );
  }


  /**** methods to help create queries ****/

  // sql representing current date/time
  //function date_now() {
  //return "now()";
  //}

  // $bit should be a number with only one bit set
  //function bit_set($field,$bit) {
  // return "(".$field."%".($bit<<1).">=".$bit.")";
  //}
  
  // $bit should be a number with only one bit set
  //function bit_unset($field,$bit) {
  // return "(".$field."%".($bit<<1)."<".$bit.")";
  //}

}

// backwards compatibility
function db_connect($name,$host,$login,$password) {
  $conn = new mysql_connection($host,$login,$password,$name);
  if ($conn->handle)
    register_shutdown_function(array($conn,"close"));
  else
    $conn=false;
  return $conn;
}


// connect to database
$conn = new mysql_connection($db_host,$db_login,$db_password,
			     $db_name,$db_persist);
if (!$conn->handle) {
  if (!$db_conn_error)
    die("Cannot connect to MySQL database '$db_name'"); //STRING
  $conn=false;
}
else {
  register_shutdown_function(array($conn,"close"));
  $conn->set_error_function("db_error_function");
  if ($DEBUG_LEVEL>0)
    $conn->track_queries();
}


?>