
December 29th, 2003
04:21 AM
MySQL Database Abstraction Class
I have made a MySQL database abstraction class for public use. If you would like to use it, go right ahead, no credits necessary.
http://216.120.229.7/mysql.class.phps

December 29th, 2003
07:16 AM
whoa, wtf?
Status: Offline!
not bad
___________________
Fomerly known as lasnaranjas. Holler.


December 29th, 2003
07:38 AM

Here's a class I use, based on Justin Vincent's ezSQL class:
<?php
// Author: Justin Vincent (justin@visunet.ie)
// Web: php.justinvincent.com
// Name: ezSQL
// Desc: Class to make it very easy to deal with mySQL.
// the main class
class db
{
// DB constructor - connects to the server and selects a database
function db()
{
$this->dbh = @mysql_connect('server', 'username', 'password');
if (!$this->dbh)
{
trigger_error(mysql_error());
}
if (!@mysql_select_db('dbname', $this->dbh))
{
trigger_error(mysql_error());
}
}
// clear vars from previous query
function flush()
{
$this->last_result = null;
$this->col_info = null;
$this->last_query = null;
$this->eof = true;
$this->y = 0;
}
// basic query
function query($query)
{
// flush cached values..
$this->flush();
// perform the query via std mysql_query function..
$this->result = mysql_query($query, $this->dbh);
if (!$this->result)
{
// if there is an error then take note of it..
trigger_error(mysql_error($this->dbh));
}
// get the sql command
$command = substr(strtolower($query), 0, 7);
if ($command == 'insert ' || $command == 'delete ' || $command == 'update ')
{
$this->rowsaffected = mysql_affected_rows($this->dbh);
// this gets the insert ID
if ($command == 'insert ')
{
$this->insertid = mysql_insert_id($this->dbh);
}
}
// see if it was an select statement..
if ($command == 'select ')
{
// store query results
return new Resultset($this->result, $this->dbh);
}
}
}
// results set class
class resultset
{
var $numrows;
var $eof;
var $rows;
var $dbh;
var $currentrow = 0;
// constructor, sets row count etc.
function resultset($result, $dbh)
{
$i=0;
// input rows into local row array
while ($row = @mysql_fetch_row($result))
{
if ($row == false)
{
trigger_error(mysql_error($dbh));
}
$this->rows[$i++] = $row;
}
// log number of rows the query returned
$this->numrows = $i;
// free up the results
@mysql_free_result($result);
// decide whether we need to set end of file
if ($i)
{
$this->eof = false;
}
else
{
$this->eof = true;
}
}
// get one row from the DB
function row($colindex=0)
{
if ($this->currentrow < $this->numrows)
{
return $this->rows[$this->currentrow][$colindex];
}
else
{
return false;
}
}
// move to next row in result set
function movenext()
{
if ($this->currentrow < ($this->numrows - 1))
{
$this->currentrow++;
}
else
{
$this->eof = true;
}
}
function move($rownumber)
{
if ($rownumber > $this->numrows)
{
$this->eof = true;
}
elseif ($rownumber > 0)
{
$this->currentrow = $rownumber;
}
}
}
?>

December 29th, 2003
01:24 PM
with Mr. Jones
Status: Offline!
I'm writing a tutorial on making mine later today
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

December 29th, 2003
02:41 PM
I lived, Ill die
Status: Offline!
Jon, you ripped the class I sent for for Dark StarBB 
___________________
<?php signature(); ?>

December 29th, 2003
08:21 PM
lol you retard, I wrote the class for Dark Star BB :P

December 30th, 2003
12:59 AM
I lived, Ill die
Status: Offline!
Originally posted by Jon Mooring
lol you retard, I wrote the class for Dark Star BB :P
Only becuase I wouldnt add support for cached queries and query timing. Since so many common users want to know how much time queries took 
___________________
<?php signature(); ?>

December 30th, 2003
01:35 AM
I lived, Ill die
Status: Offline!
Originally posted by Jon Mooring
eat me
No thankyou Jon. But perhaps one of the other 4 Dark Star Group developers might?
___________________
<?php signature(); ?>

December 30th, 2003
01:49 AM
Phil in your tuts at the very bottom after the table you made a typo, you wrote </html? instead of </html> ... thought you should know. 