/** * Create a new WordPress website from scratch * * @Given /^\w+ have a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { global $wp_rewrite; $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $hash = $table->getHash(); $row = $hash[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); \PHPUnit_Framework_Assert::assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); //This is a bit of a hack, we don't care about the notification e-mails here so clear the inbox //we run the risk of deleting stuff we want! $this->inboxFactory->getInbox($email)->clearInbox(); $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); }
/** * @param $sql string * // todo: add fetch types * @param string $fetch_type string [assoc, object, ...] * @return array */ public function query($sql, $fetch_type = 'assoc') { // todo: check sql string $this->mysqli->query($sql); $rows = array(); $result = $this->mysqli->query($sql); if (!$result) { $this->loger->addLog(LOG_ERR, mysqli_error($this->mysqli)); // todo: goto html output die; } switch ($fetch_type) { default: case 'assoc': while ($row = $result->fetch_assoc()) { $rows[] = $row; } break; case 'object': while ($row = $result->fetch_object()) { $rows[] = $row; } break; } return $rows; }
public static function prep($value) { if (MAGIC_QUOTES_ACTIVE) { // If magic quotes is active, remove the slashes $value = stripslashes($value); } // Escape special characters to avoid SQL injections $value = self::$_connection->real_escape_string($value); return $value; }
public function connect() { $connect = ''; try { $connect = new Mysqli(HOST, USERNAME, PASSWORD, DATABASE); $connect->set_charset(CHARSET); } catch (Exception $ex) { echo $ex->getMessage(); } return $connect; }
/** * [connect 数据库连接] * @return [type] [description] */ private function connect(){ if(is_null(self::$link)){ $db = C('DB_DATABASE'); if(empty($db))echo "请先配置数据库"; $link = new Mysqli(C('DB_HOST'),C('DB_USER'),C('DB_PASSWORD'),C('DB_DATABASE')); if($link->connect_error){ echo "数据库连接错误,请检查配置项"; } $link->set_charset(C('DB_CHARSET')); self::$link = $link; } }
protected function __connect() { $config = $this->getConfig(); $con = new \Mysqli($config->getHost(), $config->getUsername(), $config->getPassword(), $config->getDatabase(), sprintf('%s', $config->getPort()), $config->getSocket() ? $config->getSocket() : NULL); if ($con->connect_errno) { $msg = 'Could not connect to database "%s" at host %s:%s'; $msg = sprintf($msg, $config->getDatabase(), $config->getHost(), $config->getPort()); throw new \RuntimeException($msg); } $charset = $config->getCharset(); $charset = empty($charset) ? 'utf8' : $charset; $con->set_charset($charset); return $con; }
/** * [_connect 链接数据库] * @return [type] [description] */ private function _connect() { if (is_null(self::$link)) { $db = C("DB_DATABASE"); if (empty($db)) { halt("请先配置数据库!"); } $link = new Mysqli(C('DB_HOST'), C('DB_USER'), C('DB_PASSWORD'), $db, C('DB_PORT')); if ($link->connect_error) { halt("数据库连接出错,请检查数据库配置"); } $link->set_charset(C("DB_CHARSET")); self::$link = $link; } }
/** * Revert this migration */ public function runDown() { foreach ($this->buildPredown() as $query) { Output::verbose('PREDOWN: ' . $query); if ($this->db->query($query)) { Output::verbose("Ok"); } else { Output::verbose($this->db->error); } } foreach ($this->buildDown() as $query) { Output::verbose('DOWN:' . $query); $this->db->query($query); } foreach ($this->buildPostdown() as $query) { Output::verbose('POSTDOWN: ' . $query); if ($this->db->query($query)) { Output::verbose("Ok"); } else { Output::verbose($this->db->error); } } $verT = Helper::get('versiontable'); $rev = $this->getRev(); $query = "DELETE FROM `{$verT}` WHERE `rev`={$rev}"; Output::verbose($query); $this->db->query($query); }
public function query($sql, $mode = MYSQLI_STORE_RESULT) { $this->_QSQL[] = $sql; Mdl_Mysql_Safecheck::checkquery($sql); if ($rs = $this->query($sql, $mode)) { return new Mdl_Mysqli_Result($rs); } $this->_ERR[] = $this->errno . ':' . $this->error; return false; $this->connect(); if (__CFG::DEBUG) { $starttime = microtime(true); } $rs = parent::query($sql, $mode); if (__CFG::DEBUG) { $errno = $this->errno; $exec_time = number_format(microtime(true) - $starttime, 6); $this->total_exec_time += $exec_time; $this->_QSQL[] = array($sql, $exec_time, $this->link, $errno); if ($errno > 0) { $this->_ESQL[] = array($sql, $this->mysql_debug_backtrace(), $errno, $this->error); } } if (preg_match("/(SELECT|SHOW|DESCRIBE|EXPLAIN)\\s+/i", $sql, $match)) { return new Mdl_Mysqli_Result($rs); } return $rs; }
function RegisterMember(User $newUser, $RegDate, $name, $image) { global $connection; // if (!find_member($Lname,$DOB)) { $query = "INSERT INTO members(id,Lname,Fname,Title,Gender,DOB,MemberImageName,MemberImage,Phone,Email,Program,Year,Hall,Parish,Subgroups,RegDate) \n\tVALUES(\n\t\t'',\n\t\t'{$newUser->getLastName()}',\n\t\t'{$newUser->getFirstName()}',\n\t\t'{$newUser->getTitle()}',\n\t\t'{$newUser->getGender()}',\n\t\t'{$newUser->getDateOfBirth()}',\n\t\t'{$name}',\n\t\t'{$image}',\n\t\t'{$newUser->getPhoneNumber()}',\n\t\t'{$newUser->getEmail()}',\n\t\t'{$newUser->getProgram()}',\n\t\t'{$newUser->getYear()}',\n\t\t'{$newUser->getHall()}',\n\t\t'{$newUser->getParish()}',\n\t\t'{$newUser->getSubGroup()}',\n\t\t'{$RegDate}'\n\t\t)"; // mysql_query($query,$connection); // // confirm_query($result_set); // if (mysql_affected_rows() == 1) { // echo "success"; // } // else { // echo "err2"; // } $mysqli = new Mysqli('localhost', 'root', 'PASSword1', 'paxromanadata'); return $mysqli->query($query); }
function __construct($config = array()) { if (empty($config)) { $config = array('server' => 'localhost', 'user' => 'root', 'password' => '', 'database' => 'test'); } parent::__construct($config['server'], $config['user'], $config['password'], $config['database']); }
public function query($query, $mode = MYSQLI_STORE_RESULT) { $res = parent::query($query, $mode); if (!$res) { throw new SphinxException($this->error); } return $res; }
/** * Free the resultset from memory and remove its reference * * @return null */ public function free() { if (!$this->isHandle()) { return; } $this->handle->free(); $this->handle = null; }
/** * @param string $query * @param array $sqlValues * @return bool|MySqliStatementExtended */ public function prepare($query, $sqlValues = array()) { if (preg_match('#:([a-zA-Z0-9_]+)#', $query)) { $prepared = preg_replace('#:([a-zA-Z0-9_]+)#', '?', $query); } else { $prepared = $query; } return parent::prepare($prepared) ? new MySqliStatementExtended($this, $prepared, $sqlValues, $query) : false; }
/** * Returns the custom table's name for a module * * @param string $module Module's name * * @throws \InvalidArgumentException * * @return string Returns the table name */ public function getModuleCustomTable($module) { $sugarBean = $this->getBean($module); $customTable = $sugarBean->get_custom_table_name(); $data = $this->db->query("SHOW TABLES LIKE '{$customTable}'"); if (empty($data)) { return ''; } return $customTable; }
/** * Create a new WordPress website from scratch * * @Given /^\w+ have|has a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $row = $table->getHash()[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); }
/** * 过滤值 * * @param string $value * @return string */ public function parseValue($value) { if (function_exists('mysql_real_escape_string') and is_resource($this->db->getCurrentLink())) { return $this->db->getCurrentLink()->real_escape_string($value); } elseif (function_exists('mysql_escape_string')) { return $this->db->getCurrentLink()->escape_string($value); } else { return addslashes($str); } }
public function __construct($host, $user, $pass, $db) { @parent::__construct($host, $user, $pass, $db); try { if ($this->connect_error) { throw new Exception("Error: {$this->connect_error}"); } } catch (Exception $e) { Helper::errorHandler($e->getMessage()); } }
function __construct($host = NULL, $username = NULL, $passwd = NULL, $dbname = NULL, $port = NULL, $socket = NULL) { $this->_host = is_null($host) ? $this->_host : $host; $this->_username = is_null($username) ? $this->_username : $username; $this->_passwd = is_null($passwd) ? $this->_passwd : $passwd; $this->_dbname = is_null($dbname) ? $this->_dbname : $dbname; $this->_port = is_null($port) ? $this->_port : $port; $this->_socket = is_null($socket) ? $this->_socket : $socket; parent::__construct($this->_host, $this->_username, $this->_passwd, $this->_dbname, $this->_port); return $this; }
public function getParams(array $constants = array()) { $constants = parent::getParams($constants); if (!isset($constants['driver_options'])) { $constants['driver_options'] = array(); } if (!isset($constants['driver_options'][\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY])) { $constants['driver_options'][\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true; } return $constants; }
/** * Constructor. * * @param array $options Array of database options with keys: host, user, password, database, select. * */ public function __construct($options) { // Get some basic values from the options. $options['host'] = isset($options['host']) ? $options['host'] : 'localhost'; $options['user'] = isset($options['user']) ? $options['user'] : '******'; $options['password'] = isset($options['password']) ? $options['password'] : ''; $options['database'] = isset($options['database']) ? $options['database'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; // Finalize initialisation. parent::__construct($options); }
/** * Explictly close the handle. Can not close the handle (mysqli_stmt) * before it has been prepared. * * @throws Appfuel\Framework\Exeception when handle is already closed * @throws \Exception when trying to close before prepared * @return bool */ public function close() { if ($this->isClosed()) { return true; } if ($this->driver instanceof mysqli_stmt) { $this->driver->close(); $this->driver = null; $this->isClosed = true; return true; } return false; }
/** * Create a new WordPress website from scratch * * @Given /^\w+ have|has a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { global $wp_rewrite; $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $hash = $table->getHash(); $row = $hash[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); }
/** * [_connect 链接数据库] * @return [type] [description] */ private function _connect() { if (is_null(self::$link)) { if (empty(self::$dbConfig['DB_DATABASE'])) { exit("请先配置数据库!"); } $link = new Mysqli(self::$dbConfig['DB_HOST'], self::$dbConfig['DB_USER'], self::$dbConfig['DB_PASSWORD'], self::$dbConfig['DB_DATABASE'], self::$dbConfig['DB_PORT']); if ($link->connect_error) { exit("数据库连接出错,请检查数据库配置"); } $link->set_charset(self::$dbConfig["DB_CHARSET"]); self::$link = $link; } }
/** * @return bool */ public function close() { $status = $this->getStatus(); if (!$this->isDriver()) { return true; } if (!$this->driver->close()) { $this->setError($driver->connect_errno, $driver->connect_error); $this->setStatus('connection closed failed'); return false; } $this->setStatus('closed'); $this->isConnected = false; $this->driver = null; return true; }
/** * * @param string $sql * @throws Exception\ConnectionException * @return array */ protected function readFields($sql) { if (trim($sql) == '') { throw new Exception\EmptyQueryException(__METHOD__ . ": Error cannot handle empty queries"); } $sql = $this->getEmptiedQuery($sql); $stmt = $this->mysqli->prepare($sql); if (!$stmt) { $message = $this->mysqli->error; throw new Exception\InvalidQueryException(__METHOD__ . ": Error sql is not correct : {$message}"); } $stmt->execute(); $result = $stmt->result_metadata(); $metaFields = $result->fetch_fields(); $result->close(); $stmt->close(); return $metaFields; }
/** * {@inheritDoc} * * @throws Exception\InvalidQueryException */ public function execute($sql) { if (!$this->isConnected()) { $this->connect(); } if ($this->profiler) { $this->profiler->profilerStart($sql); } $resultResource = $this->resource->query($sql); if ($this->profiler) { $this->profiler->profilerFinish($sql); } // if the returnValue is something other than a mysqli_result, bypass wrapping it if ($resultResource === false) { throw new Exception\InvalidQueryException($this->resource->error); } $resultPrototype = $this->driver->createResult($resultResource === true ? $this->resource : $resultResource); return $resultPrototype; }
/** * Execute * * @param null|array|ParameterContainer $parameters * @throws Exception\RuntimeException * @return mixed */ public function execute($parameters = null) { if (!$this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ if (!$this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; } else { $this->parameterContainer = new ParameterContainer(); } } if (is_array($parameters)) { $this->parameterContainer->setFromArray($parameters); } /** END Standard ParameterContainer Merging Block */ if ($this->profiler) { $this->profiler->profilerStart($this); } $args = $this->parameterContainer->getPositionalArray(); $argArray = [$this->resource]; if (!empty($args)) { $argArray = array_merge($argArray, $args); } //die(var_dump($argArray)); $response = call_user_func_array('ibase_execute', $argArray); if ($this->profiler) { $this->profiler->profilerFinish(); } if ($response === false) { throw new Exception\RuntimeException(ibase_errmsg()); } $result = $this->driver->createResult($response); return $result; }
/** * Run the actual query with deadlock checks * @return bool|object * @throws TransactionDeadlockException */ protected function runQuery() { $numRetry = 0; do { $returned = $this->isSingleQuery ? $this->connection->query($this->sqlQuery) : $this->connection->multi_query($this->sqlQuery); if ($returned) { break; } $errno = mysqli_errno($this->connection); if ($errno != '1205' && $errno != '1213') { break; } // innodb deadlock; retry or if in transaction throw exception if ($this->isTransaction) { $this->rollback(); throw new TransactionDeadlockException('Transaction deadlock.'); } if ($numRetry == 5) { sleep(1); } ++$numRetry; } while ($numRetry < 10); return $returned; }
/** * * @param string $sql * @throws Exception\ConnectionException */ protected function readFields($sql) { if (trim($sql) == '') { throw new Exception\EmptyQueryException(__METHOD__ . ": Error cannot handle empty queries"); } $sql = $this->makeQueryEmpty($sql); $stmt = $this->mysqli->prepare($sql); if (!$stmt) { $message = $this->mysqli->error; throw new Exception\InvalidQueryException(__METHOD__ . ": Error sql is not correct : {$message}"); } $stmt->execute(); // to check if query is empty /* $stmt->store_result(); var_dump($stmt->num_rows); var_dump( */ $result = $stmt->result_metadata(); $metaFields = $result->fetch_fields(); $result->close(); $stmt->close(); return $metaFields; }