Location: PHPKode > projects > FiForms Framework > FiForms/FiForms-includes/FiConnect_MySQL.inc.php
<?php
/*
*******************************************************************************

    FiConnect -- A database abstraction layer to facilitate querying a 
    database in PHP

    Copyright (C) 2004-2008  Daniel McFeeters

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    The original author of this library can be contacted at the following
    address:

    Daniel McFeeters
    182 Baker Rd.
    Faubush, KY 42544-6526
    email: databases [at] fiforms [dot] org
    http://www.fiforms.org/

*******************************************************************************
FiConnect_MySQL.inc.php

FiConnect_MySQL Class Library

*******************************************************************************
*/

    require_once("FiConnect_DB.inc.php");

    class FiConnect_MySQL extends FiConnect_DB
    {
        var $connection; // connection ID 
        var $resultResource; // variable to store last SQL result

        function FiConnect_MySQL()
        {
            $this->FiConnect_DB();  // call parent constructor
        } // function FiConnect_MySQL

        function connect()
        {
            $this->connection = 
                mysql_connect($this->server,
                              $this->auth->username,
                              $this->auth->passwd);
            if($this->connection)
                $this->connected = TRUE;
            else
                $this->throwError("Error connecting");
        if($this->default_db)
        {
                @mysql_select_db($this->default_db,$this->connection)
                    or $this->throwError("Error selecting database.");
        }
        } // function connect
        
        function query($sql)
        {
            if(!$this->connected)
            {
                $this->connect();
            }
            $this->resultResource = @mysql_query($sql,$this->connection) 
                or $this->throwError('Error Executing Query: '.mysql_error());
        } // function query
    
    function list_dbs()
    {
        if(!$this->connected)
            {
                $this->connect();
            }
        $this->resultResource = @mysql_list_dbs($this->connection) 
                or $this->throwError('Error Listing Databases: '.mysql_error());
    }
    
    
        function result($row,$field)
        {
            if($this->resultResource)
                return @mysql_result($this->resultResource,$row,$field);
            else
                $this->throwError("Error getting data");
        } // function result

        function fetch_array($resultType = MYSQL_ASSOC)
        {
            if($this->resultResource)
                return @mysql_fetch_array($this->resultResource,$resultType);
            else
                $this->throwError("Error getting data");
        }
        
        function formatResult($header,$repeat,$footer)
        {
            $resultArray = @mysql_fetch_array($this->resultResource,MYSQL_ASSOC);
            if($resultArray)
            {
                $ftext = fillVars($resultArray,$header,true);
                $ftext .= fillVars($resultArray,$repeat,true);
                $footertext = fillVars($resultArray,$footer,true);
                while($resultArray = 
                    @mysql_fetch_array($this->resultResource,MYSQL_ASSOC))
                {
                    $ftext .= fillVars($resultArray,$repeat,true);
                }
                $ftext .= $footer;
            }
            return $ftext;

        } // function formatResult
        
    } // class MysqlConnection
?>
Return current item: FiForms Framework