Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   Easy MySqL class (https://novahq.net/forum/showthread.php?t=26107)

JonM 05-28-2005 12:28 AM

Easy MySqL class
 
learned this from one of p's scripts so you know it's good, anyways i'm using it :p so now u know it's REALLY good... haha jk any ways:

PHP Code:

class site_Template {
    var 
$userdata = array();
    var 
$db;
    var 
$site = array();
    var 
$mysqldata = array();
    var 
$key;
    var 
$page;
    
##################  MySQL Stuff Before we go through with the site  ##################
    
function connect($host$m_user$m_pass$m_db$m_per){
        
$this->mysqldata['host'] = $host;
        
$this->mysqldata['username'] = $m_user;
        
$this->mysqldata['password'] = $m_pass;
        
$this->mysqldata['db'] = $m_db;
        
$this->mysqldata['persistency'] = $m_per;
        if(
$this->mysqldata['persistency']){
            
$this->mysqldata['connect'] = @mysql_pconnect($this->mysqldata['host'],$this->mysqldata['username'],$this->mysqldata['password']);
        } else {
            
$this->mysqldata['connect'] = @mysql_connect($this->mysqldata['host'],$this->mysqldata['username'],$this->mysqldata['password']);
        }
        if((
$this->mysqldata['connect']) AND ($this->mysqldata['db'])){
            if(@
mysql_select_db($mysqldata['db'],$mysqldata['connect'])){
                return 
true;
            } else {
                return 
false;
            }
        }
        return 
false;
    }
    
    function 
fetch($query=""){
        
$query = @mysql_fetch_array($query);
        return(
$query);
    }
    
    function 
query($query="",$sup=""){
        if(
$sup){
            
$query = @mysql_query($query,$this->mysqldata['connect']);
        } else {
            
$query = @mysql_query($query,$this->mysqldata['connect']) or die("<b>Debug</b>".mysql_error()."<b>");
        }
        return(
$query);
    }
    
    function 
rows($query=""){
        
$query = @mysql_num_rows($query);
        return(
$query);
    }
    
    function 
free($query=""){
        @
mysql_free_result($query);
    }
    
    function 
result($query=""$sup=""){
        
$query $this->query($query,$sup);
        
$result $this->fetch($query,$sup);
        
$this->free($query);
        return(
$result);
    }
    
    function 
getrows($query=""$sup=""){
        
$query $this->query($query,$sup);
        
$rows $this->rows($query);
        
$this->free($query);
        return(
$result);
    }
    
    function 
disconnect() {
        @
mysql_close($this->mysqldata['connect']);
    }


of course i made my changes but o welll... anyways enjoy! O yeah , hta'ts not even close to the 1/4 th of my full class for my site ;) i'm working hard :D

atholon 05-28-2005 09:45 AM

:) that is how I am learning.

I am looking at the queries from Simple Squad site and his upload script :)

IcIshoot 05-28-2005 09:48 AM

Personally, I like the mysql class that comes with phpnuke.

Real simple.

Plus it has a few more information gathering functions,

I would post it but it is 300+ lines long.

Scott 05-28-2005 11:29 AM

it is a really simple class, i use it because it saves mucho time.. you can also make it to filter / log false querys, like I do here on novahq... that way you can use the class to protect, and silently log mysql errors..


All times are GMT -5. The time now is 03:11 PM.

Powered by vBulletin®