Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1535 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

mySQL database class (opinions/suggestions)

Thread title: mySQL database class (opinions/suggestions)
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
03-08-2005, 04:35 AM
#1
mike.fro is offline mike.fro
mike.fro's Avatar
Status: I love this place
Join date: Mar 2005
Location: Burnsville
Expertise: Design
Software:
 
Posts: 674
iTrader: 5 / 100%
 

mike.fro is on a distinguished road

  Old  mySQL database class (opinions/suggestions)

Hey Everyone,
I'm in the process of creating a nice mySQL database class and am interested in your opinions on it so far. Please let me know what you think and what else you feel should be added/fixed. This was coded in PHP5.

mysql.class.php:
PHP Code:
<?php

/* mySQL Database Class 
   Mike Froseth
   Testing Purposes Only (for now!)
*/

class mysql {
    
    private 
$linkid;     // mySQL link identifier
    
private $host;       // mySQL server host
    
private $user;       // mySQL user
    
private $pswd;       // mySQL password
    
private $db;         // mySQL database
    
private $result;     // mySQL result
    
private $querycount// Total queries executed
    
    /* Class constructor. Initializes the $host, $user, $pswd
       and $db fields. */
    
    
function __constuct($host$user$pswd$db) {
        
$this->host $host;
        
$this->user $user;
        
$this->pswd $pswd;
        
$this->db $db;
        
    }
    
    
/* Connects to the mySQL database server */
    
function connect() {
        try {
            
$this->linkid = @mysql_connect($this->host,$this->user,$this->pswd);
            if(! 
$this->linkid)
              throw new 
Exception("Could not connect to the mySQL server.");
        }
        catch (
Exception $e) {
            die(
$e->getMessage());
            
        }
    }
    
    
/* Selects the mySQL database. */
    
function select() {
        try {
            if (! @
mysql_select_db($this->db$this->linkid))
               throw new 
Exception("Could not connect to the mySQL database.");
               
        }
        catch (
Exception $e) {
            die(
$e->getMessage());
            
        }
    }
    
    
/* Execute database query */
    
function query($query) {
        try {
            
$this->result = @mysql_query($query,$this->linkid);
            if (! 
$this->result)
               throw new 
Exception("The database query failed.");
               
        }
        catch (
Exception $e) {
            echo(
$e->getMessage());
            
        }
        
$this->querycount++;
        return 
$this->result;
        
    }
    
/* Determine total rows affected by query. */
    
function affectedRows() {
        
$count = @mysql_num_rows($this->linkid);
        return 
$count;
        
    }
    
    
/* Determine total rows returned by query. */
    
function numRows() {
        
$count = @mysql_num_rows($this->result);
        return 
$count;
        
    }
    
    
/* Return query result row as an object. */
    
function fetchObject() {
        
$row = @mysql_fetch_object($this->result);
        return 
$row;
        
    }
    
    
/* Return query result as an indexed array. */
    
function fetchRow() {
        
$row = @mysql_fetch_row($this->result);
        return 
$row;
    }
    
    
/* Return query result row as an associative array. */
    
function fetchArray() {
        
$row = @mysql_fetch_array($this->result);
        return 
$row;
    }
    
    
/* Return total number queries executed during lifetime of this object.
       Not required, but interesting nonetheless. */
    
function numQueries() {
        return 
$this->querycount;
    }
}
?>
Thats it so far. Please let me know what you think and any suggestions you might have.

Regards,

     


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed