示例#1
0
文件: mysql.php 项目: sonicmaster/RPG
function doquery($query, $table, $fetch = false)
{
    /*
     * Throw notices on doquery() calls.
     */
    if (defined(DEPRECATION)) {
        $backtrace = debug_backtrace();
        $message = "Function doquery() called from file '%s', line %d.";
        trigger_error(sprintf($message, $backtrace[0]['file'], $backtrace[0]['line']), $fetch ? E_USER_NOTICE : E_USER_WARNING);
    }
    /**
     * @var Zend_Db_Adapter_Abstract
     */
    $instance = Legacies_Database::getInstance();
    $sql = str_replace('{{table}}', Legacies_Database::getDeprecatedTable($table), $query);
    if ($fetch) {
        try {
            /**
             * @var Zend_Db_Statement_Abstract
             */
            $statement = $instance->query($sql);
        } catch (Zend_Db_Exception $e) {
            trigger_error($e->getMessage() . PHP_EOL . "<br /><pre></code>{$sql}<code></pre><br />" . PHP_EOL, E_USER_WARNING);
        }
        return $statement->fetch(Zend_Db::FETCH_BOTH);
    } else {
        if (($statement = mysql_query($sql, $instance->getConnection())) === false) {
            trigger_error(mysql_error($instance->getConnection()) . PHP_EOL . "<br /><pre></code>{$sql}<code></pre><br />" . PHP_EOL, E_USER_WARNING);
        }
        return $statement;
    }
}