<?php // KioCMS - Kiofol Content Managment System // includes/mysql.php defined('KioCMS') || exit; $cfg->system['queries'] = 0; if (DB_PDO) { try { define('OPD_DIR', ROOT . 'system/OPD/'); require OPD_DIR . 'opd.class.php'; $sql = new OPD('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . (DB_PORT ? ';port=' . DB_PORT : null), DB_USER, DB_PASS); $sql->setCacheDirectory(ROOT . CACHE_DIR); // $sql->debugConsole = true; //$sql = new MyPDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.(DB_PORT ? ';port='.DB_PORT : null), DB_USER, DB_PASS); $sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql->exec('SET NAMES utf8'); } catch (Exception $e) { exit('<div style="text-align: center;"><br /><h3>' . t('Error while connecting to SQL database!') . '</h3><code>' . $e->getMessage() . '</code></div>'); //exit('<h3>Error while connecting to SQL database!</h3><code>'.$e->getMessage().'</code><p>For more information check log file.</p>'); } } function query($content) { global $sql; return $sql->query($content); } /* mysql_connect(DB_HOST, DB_USER, DB_PASS) || die(mysql_error()); mysql_select_db(DB_NAME) || die(mysql_error()); function sql_query($query)
public function query($statement, $fetchMode = PDO::FETCH_ASSOC) { $this->beginDebugDefinition($statement); if ($this->cache) { $this->cache = false; if (!is_null($this->cachePeroid)) { if (@filemtime($this->cacheDir . $this->cacheId . '.php') + $this->cachePeroid > time()) { $this->cachePeroid = NULL; return new opdCachedStatement($this, true, $this->cacheId); } $this->cachePeroid = NULL; } else { if (file_exists($this->cacheDir . $this->cacheId . '.php')) { return new opdCachedStatement($this, true, $this->cacheId); } } $this->makeConnection(); $this->startTimer(true, false); $result = $this->pdo->query($statement); $this->endTimer(); OPD::$lastQuery = $statement; $result->setFetchMode($fetchMode); return new opdCachedStatement($this, false, $result, $this->cacheId); } else { $this->cache = false; $this->makeConnection(); $this->startTimer(false, false); $result = $this->pdo->query($statement); $this->endTimer(); OPD::$lastQuery = $statement; $result->setFetchMode($fetchMode); return new OPDStatement($this, $result); } }