Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

53 users online



MySQL Database Abstraction Class

MySQL Database Abstraction Class

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
Jon_Mooring

Jon_Mooring

Status: Offline!

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

phpmonkey

phpmonkey

whoa, wtf?
Status: Offline!

not bad

___________________

Fomerly known as lasnaranjas. Holler.
http://card.mygamercard.net/gelsig/blackdood.png

JimT

JimT

Status: Offline!

Here's a class I use, based on Justin Vincent's ezSQL class:

PHP:

<?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->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), 07);

        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;
        }
    }
}

?>

Phil

Phil

with Mr. Jones
Status: Offline!

I'm writing a tutorial on making mine later today

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Tristan_Wells

Tristan_Wells

I lived, Ill die
Status: Offline!

Jon, you ripped the class I sent for for Dark StarBB Tongue

___________________

<?php signature(); ?>

Jon_Mooring

Jon_Mooring

Status: Offline!

lol you retard, I wrote the class for Dark Star BB :P

Tristan_Wells

Tristan_Wells

I lived, Ill die
Status: Offline!
Quote:

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 Tongue

___________________

<?php signature(); ?>

Jon_Mooring

Jon_Mooring

Status: Offline!
Quote:

Originally posted by Tristan Wells
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 Tongue

eat me Grin

Tristan_Wells

Tristan_Wells

I lived, Ill die
Status: Offline!
Quote:

Originally posted by Jon Mooring
eat me Grin


No thankyou Jon. But perhaps one of the other 4 Dark Star Group developers might?

___________________

<?php signature(); ?>

Will742

Will742

Status: Offline!

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. Tongue

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0118 seconds.