$value) { if (!DatabaseFactory::isDebug($connectionid)) { unset($log[$connectionid]); } } //print_p($log); $html = "View Queries\n"; $html .= "\n"; $html .= "\n"; $html .= ""; echo $html; } }); /** * Send a database query * * @param string $query SQL * @param array $parameters * * @return mixed The result of query or FALSE on error */ function dbquery($query, array $parameters = []) { // Temporary check to detect the bug in installer return DatabaseFactory::getConnection('default')->query($query, $parameters); } /** * Count the number of rows in a table filtered by conditions * * @param string $field Parenthesized field name * @param string $table Table name * @param string $conditions conditions after "where" * @param array $parameters * * @return boolean */ function dbcount($field, $table, $conditions = "", array $parameters = []) { return DatabaseFactory::getConnection('default')->count($field, $table, $conditions, $parameters); } /** * Fetch the first column of a specific row * * @param mixed $result * @param int $row * * @return mixed */ function dbresult($result, $row) { return DatabaseFactory::getConnection('default')->fetchFirstColumn($result, $row); } /** * Count the number of affected rows by the given query * * @param mixed $result * * @return int */ function dbrows($result) { return DatabaseFactory::getConnection('default')->countRows($result); } /** * Fetch one row as an associative array * * @param mixed $result * * @return array Associative array */ function dbarray($result) { return DatabaseFactory::getConnection('default')->fetchAssoc($result); } /** * Fetch one row as a numeric array * * @param mixed $result * * @return array Numeric array */ function dbarraynum($result) { return DatabaseFactory::getConnection('default')->fetchRow($result); } /** * Connect to the database * * @param string $db_host * @param string $db_user * @param string $db_pass * @param string $db_name * @param int $db_port * @param boolean $halt_on_error If it is TRUE, the script will halt in case of error * * @return array */ function dbconnect($db_host, $db_user, $db_pass, $db_name, $db_port = 3306, $halt_on_error = FALSE) { $connection_success = TRUE; $dbselection_success = TRUE; try { DatabaseFactory::connect($db_host, $db_user, $db_pass, $db_name, [ 'debug' => DatabaseFactory::isDebug('default'), 'port' => $db_port ]); } catch (\Exception $e) { $connection_success = $e instanceof SelectionException; $dbselection_success = FALSE; if ($halt_on_error and !$connection_success) { die("Unable to establish connection to MySQL
".$e->getCode()." : ".$e->getMessage()); } else if ($halt_on_error) { die("Unable to select MySQL database
".$e->getCode()." : ".$e->getMessage()); } } return [ 'connection_success' => $connection_success, 'dbselection_success' => $dbselection_success ]; } /** * Get the next auto_increment id of a table * * Try to avoid the use of it! {@link dblastid()} after insert * is more secure way to get the id of an existing record than * get just a potential id. * * @param string $table * * @return int|false */ function dbnextid($table) { return DatabaseFactory::getConnection('default')->getNextId($table); } /** * Get the last inserted auto increment id * * @return int */ function dblastid() { return (int)DatabaseFactory::getConnection('default')->getLastId(); } /** * Get the AbstractDatabase instance * * @return AbstractDatabaseDriver */ function dbconnection() { try { return DatabaseFactory::getConnection('default'); } catch (\Exception $e) { ## Do nothing to hide all errors ini_set('display_errors', FALSE); return NULL; } }