Location: PHPKode > projects > Gnew > Gnew-2013.1/includes/mysql.php
<?php
// -----------------------------------------------------------------------------
// $Id: mysql.php 707 2013-04-01 14:41:30Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// This program 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 3 of the License, or (at your option) any later
// version.
//
// This program 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 program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

if (!class_exists('mysqli'))
{
    exit('The mysqli class is not available.');
}
else
{
    class mysql extends mysqli
    {
        // ------------------------------
        private $host = SQL_HOST;
        private $user = SQL_USER;
        private $password = SQL_PASSWORD;
        private $database = SQL_DATABASE;
        private $port = SQL_PORT;
        // ------------------------------
        private $num_queries = 0;
        private $result;
        // ------------------------------

        public function __construct()
        {
            return @parent::__construct($this->host, $this->user, $this->password, $this->database, $this->port);
        }

        public function close()
        {
            return @parent::close;
        }

        private function error($query)
        {
            if ($this->connect_errno)
            {
                exit('Connection to MySQL server has failed.');
            }
            if (!$this->result)
            {
                printf('Error in SQL query "%s".', $query);
                exit();
            }
        }

        public function fetch()
        {
            return $this->result ? $this->result->fetch_assoc() : false;
        }

        public function fetch_all()
        {
            if ($this->result)
            {
                if (method_exists('mysqli_result', 'fetch_all'))
                {
                    return $this->result->fetch_all(MYSQLI_ASSOC);
                }
                else
                {
                    $rows = array();
                    $key = 0;
                    while ($i = $this->fetch())
                    {
                        $rows[$key] = $i;
                        $key++;
                    }
                    return $rows;
                }
            }
            else
            {
                return false;
            }
        }

        public function insert_id()
        {
            return $this->insert_id;
        }

        public function num_queries()
        {
            return $this->num_queries;
        }

        public function num_rows()
        {
            return $this->result ? $this->result->num_rows : false;
        }

        public function query($query)
        {
            if (!empty($query))
            {
                $this->num_queries++;
                $this->result = @parent::query($query);
                if ($this->result)
                {
                    return $this->result;
                }
                else
                {
                    return $this->error($query);
                }
            }
            else
            {
                return false;
            }
        }
    }
}

?>
Return current item: Gnew