Location: PHPKode > projects > Gnew > Gnew-2013.1/includes/sqlite.php
<?php
// -----------------------------------------------------------------------------
// $Id: sqlite.php 698 2013-03-30 05:32:18Z 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('SQLite3'))
{
    exit('The SQLite3 class is not available.');
}
else
{
    class sqlite extends SQLite3
    {
        // ------------------------------
        private $database = SQL_DATABASE;
        // ------------------------------
        private $num_queries = 0;
        private $result;
        // ------------------------------

        public function __construct()
        {
            $this->open($this->database);
            $this->busyTimeout(6000);
        }

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

        private function error($query)
        {
            // http://www.sqlite.org/c3ref/c_abort.html
            if ($this->lastErrorCode())
            {
                exit('Connection to SQLite database has failed.');
            }
            if (!$this->result)
            {
                printf('Error in SQL query "%s".', $query);
                exit();
            }
        }

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

        public function fetch_all()
        {
            $rows = array();
            $key = 0;
            if ($this->result)
            {
                while ($i = $this->result->fetchArray(SQLITE3_ASSOC))
                {
                    $rows[$key] = $i;
                    $key++;
                }
                return $rows;
            }
            else
            {
                return false;
            }
        }

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

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

        public function num_rows()
        {
            $num_rows = 0;
            while ($this->fetch())
            {
                $num_rows++;
            }
            return $num_rows;
        }

        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