trashbin/include/mysql.class.php

120 lines
2.9 KiB
PHP

<?php
class MySQL {
var $db_host;
var $db_user;
var $db_pwd;
var $db_name;
var $queries = 0;
var $connections = 0;
var $linki;
function set($db_host, $db_user, $db_pwd, $db_name)
{
$this->db_host = $db_host;
$this->db_user = $db_user;
$this->db_pwd = $db_pwd;
$this->db_name = $db_name;
}
function connect()
{
// connect to mysql
$this->linki = mysql_connect($this->db_host, $this->db_user, $this->db_pwd)
or die("Could not connect to mysql server");
// connect to the database
mysql_select_db($this->db_name, $this->linki)
or die("Database: database not found");
$this->connections++;
// return $db_link for other functions
//return $linki;
}
function query($sql)
{
//echo $sql . "<br>";
if (!isset($this->linki)) {
$this->connect();
}
$result = mysql_query($sql, $this->linki)
or die("Invalid query: " . mysql_error());
// used for other functions
$this->queries++;
return $result;
}
function fetch_array($result)
{
// create an array called $row
$row = mysql_fetch_array($result);
// return the array $row or false if none found
return $row;
}
function escape($string) {
return mysql_real_escape_string($string,$this->linki);
}
function fetch_assoc($result)
{
// create an array called $row
$row = mysql_fetch_assoc($result);
// return the array $row or false if none found
return $row;
}
// function fetch_row($result)
// {
// // create an array called $row
// $row = mysql_fetch_row($result);
// // return the array $row or false if none found
// return $row;
// }
function num_rows($result)
{
// determine row count
$num_rows = mysql_num_rows($result);
// return the row count or false if none foune
return $num_rows;
}
function insert_id()
{
// connect to the database
//$link = $this->connect();
// Get the ID generated from the previous INSERT operation
$last_id = mysql_insert_id($this->linki);
// return last ID
return $last_id;
}
function num_fields($result)
{
$result = mysql_num_fields($result);
return $result;
}
// function field_name($result, $index)
// {
// // query with the return of $result
// $result = mysql_field_name($result, $index);
// return $result;
// }
//
// function tablename($result, $index)
// {
// // query with the return of $result
// $result = mysql_tablename($result, $index);
// return $result;
// }
//
// function list_tables($dbase)
// {
// $result = mysql_list_tables($dbase);
// return $result;
// }
}
?>