PHP Classes

File: mysql.addon.php

Recommend this page to a friend!
  Packages of Tomas B   phpEngine   mysql.addon.php   Download  
File: mysql.addon.php
Role: Auxiliary script
Content type: text/plain
Description: MySQL functions
Class: phpEngine
Regular expression match based template engine
Author: By
Last change: No changes
Date: 22 years ago
Size: 2,124 bytes
 

 

Contents

Class file image Download
<?php

/**    Copyright 2004 Live Web Institute Studio (lwis.net): Ingenious Web Solutions

    Licensed under "Non-Commercial License" for "Non-Commercial or Research Use": research, evaluation, personal and educational use,
    excluding use or distribution for direct or indirect commercial (including strategic) gain or advantage.    
    
    $Id: mysql.addon.php, v1.2 2004/09/17 22:19:21 Tomas Bagdanavicius Exp $
    [ MySQL database management functions - addon ]

    **/

class mysql extends phpEngine {

    var $hostname = "localhost:3306";
    var $username = "root";
    var $password = "";

    function mysql(&$a) {
        $this->e = &$a;
    }

    function connect($database = null) {
        $this->connection = @mysql_connect($this->hostname, $this->username, $this->password);

        if($database <> null)
            $this->select_db($database);

        if(!$this->connection)
            $this->notice("Failed to connect to MySQL server! ".mysql_error());
    }

    function select_db($database) {
        $this->db = @mysql_select_db($database, $this->connection);

        if(!$this->db)
            $this->notice("Failed to select database! ".mysql_error());
    }

    function query($q) {
        $this->mysql_request = @mysql_query($q);

        if(!$this->mysql_request)
            $this->notice("Invalid MySQL query! ".mysql_error());
    return $this->mysql_request;
    }

    function result($q, $line = 0) {
        if(!is_resource($q))
            $q = $this->query($q);
        $this->get_result = @mysql_result($q, $line);

        if(!$this->get_result)
            $this->notice("Failed to get MySQL result! ".mysql_error());
    return $this->get_result;
    }

    function fetch($q) {
        if(!is_resource($q))
            $q = $this->query($q);
        $num = mysql_num_rows($q);
        if($num == 0) return false;

        $results = array();
        while ($row = @mysql_fetch_assoc($q)) {
            array_push($results, $row);
        }
        mysql_free_result($q);
    return ($num > 1) ? $results : $results[0];
    }

    function disconnect() {
       $this->close_connection = @mysql_close($this->connection);

       if(!$this->close_connection)
           $this->notice("Could not disconnect from MySQL server! ".mysql_error());
    }

}
?>