/** * Perform mySQL query * * Added to the original function: logging of all queries * * @since 1.7 */ function query($query) { $select_query = strtolower(trim(current(explode(' ', $query)))); // If it is a select query on URL (YOURLS_DB_TABLE_URL) table, send to SLAVE if ($select_query == 'select' && (strstr(strtolower($query), 'from `' . YOURLS_DB_TABLE_URL . '`') != '' || strstr(strtolower($query), 'from ' . YOURLS_DB_TABLE_URL) != '')) { $dbuser = YOURLS_SLAVE_DB_USER; $dbpassword = YOURLS_SLAVE_DB_PASS; $dbname = YOURLS_SLAVE_DB_NAME; $dbhost = YOURLS_SLAVE_DB_HOST; } else { $dbuser = YOURLS_DB_USER; $dbpassword = YOURLS_DB_PASS; $dbname = YOURLS_DB_NAME; $dbhost = YOURLS_DB_HOST; } $this->dbuser = $dbuser; $this->dbpassword = $dbpassword; $this->dbname = $dbname; // Get custom port if any if (false !== strpos($dbhost, ':')) { list($dbhost, $dbport) = explode(':', $dbhost); $dbhost = sprintf('%1$s;port=%2$d', $dbhost, $dbport); } $this->dbhost = $dbhost; // $this->encoding = $encoding; $dsn = 'mysql:host=' . $dbhost . ';dbname=' . $dbname; $this->dsn = $dsn; $this->connect($dsn, $dbuser, $dbpassword); // Keep history of all queries $this->debug_log[] = $query; // Original function return parent::query($query); }
/** * Perform mySQL query * * Added to the original function: logging of all queries * * @since 1.7 */ function query($query) { // Keep history of all queries $this->debug_log[] = $query; // Original function return parent::query($query); }
<?php require "config.php"; //这里的引用来自php.ini的公用include require "ez_sql/ez_sql_core.php"; require "ez_sql/ez_sql_pdo.php"; require "smarty/Smarty.class.php"; require "comm/class/SqlText.php"; require "comm/class/Page.php"; require "comm/class/Runtime.php"; require "comm/functions.php"; require "comm/share.php"; $curr_file_name = strtolower(self()); $runtime = new runtime(); $db = new ezSQL_pdo($db_cfg["connect"], $db_cfg["user"], $db_cfg["pwd"]); if (strpos($db_cfg["connect"], "mysql") !== false) { $db->query("SET NAMES " . constant("WEB_CHARSET")); } define("SMARTY_PATH", "smarty/"); $smarty = new Smarty(); $smarty->template_dir = "html/"; $smarty->compile_dir = constant("SMARTY_PATH") . "templates_c/"; $smarty->config_dir = constant("SMARTY_PATH") . "configs/"; $smarty->cache_dir = constant("SMARTY_PATH") . "cache/"; $page = new Page(); $page->pageIndexName = "page"; $page->firstText = "首页"; $page->prevText = "上一页"; $page->nextText = "下一页"; $page->lastText = "末页"; $novalid = array();
<?php // Include ezSQL core include_once "../shared/ez_sql_core.php"; // Include ezSQL database specific component include_once "ez_sql_pdo.php"; // Initialise database object and establish a connection at the same time // db_user / db_password / db_name / db_host // If you need to specify a custom port, use notation: 'mysql:host=127.0.0.1;port=9999;dbname=some_db' $db = new ezSQL_pdo('mysql:host=db_host;dbname=db_name', 'db_user', 'db_password'); /********************************************************************** * ezSQL demo for mySQL database */ // Demo of getting a single variable from the db // (and using abstracted function sysdate) $current_time = $db->get_var("SELECT " . $db->sysdate()); print "ezSQL demo for mySQL database run @ {$current_time}"; // Print out last query and results.. $db->debug(); // Get list of tables from current database.. $my_tables = $db->get_results("SHOW TABLES", ARRAY_N); // Print out last query and results.. $db->debug(); // Loop through each row of results.. foreach ($my_tables as $table) { // Get results of DESC table.. $db->get_results("DESC {$table['0']}"); // Print out last query and results.. $db->debug(); }