コード例 #1
0
 /**
  * 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%/');
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
ファイル: database.php プロジェクト: piiskop/pstk
 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;
 }
コード例 #4
0
ファイル: Model.php プロジェクト: svintuskbd/foodAndFeed
 public function connect()
 {
     $connect = '';
     try {
         $connect = new Mysqli(HOST, USERNAME, PASSWORD, DATABASE);
         $connect->set_charset(CHARSET);
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
     return $connect;
 }
コード例 #5
0
ファイル: Model.class.php プロジェクト: happyun/SHPHP
	/**
	 * [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;
			
		}
	}
コード例 #6
0
ファイル: Connection.class.php プロジェクト: pthreat/apf-dev
 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;
 }
コード例 #7
0
ファイル: Model.class.php プロジェクト: sujinw/webPHP
 /**
  * [_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;
     }
 }
コード例 #8
0
 /**
  * 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);
 }
コード例 #9
0
ファイル: mysqli.mdl.php プロジェクト: a195474368/ejiawang
 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;
 }
コード例 #10
0
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);
}
コード例 #11
0
ファイル: user.php プロジェクト: Hellios3000/localhost
 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']);
 }
コード例 #12
0
 public function query($query, $mode = MYSQLI_STORE_RESULT)
 {
     $res = parent::query($query, $mode);
     if (!$res) {
         throw new SphinxException($this->error);
     }
     return $res;
 }
コード例 #13
0
ファイル: QueryResult.php プロジェクト: kevinlondon/appfuel
 /**
  * Free the resultset from memory and remove its reference
  *
  * @return null
  */
 public function free()
 {
     if (!$this->isHandle()) {
         return;
     }
     $this->handle->free();
     $this->handle = null;
 }
コード例 #14
0
 /**
  * @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;
 }
コード例 #15
0
ファイル: Bean.php プロジェクト: inetprocess/libsugarcrm
 /**
  * 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;
 }
コード例 #16
0
 /**
  * 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);
 }
コード例 #17
0
ファイル: Builder.php プロジェクト: Rgss/imp
 /**
  * 过滤值
  * 
  * @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);
     }
 }
コード例 #18
0
ファイル: DB.class.php プロジェクト: js2n/myBlog
 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());
     }
 }
コード例 #19
0
 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;
 }
コード例 #20
0
ファイル: PdoMysql.php プロジェクト: rafalwrzeszcz/zf2
 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;
 }
コード例 #21
0
ファイル: Mysql.php プロジェクト: edrdesigner/awf
 /**
  * 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);
 }
コード例 #22
0
ファイル: PreparedStmt.php プロジェクト: kevinlondon/appfuel
 /**
  * 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;
 }
コード例 #23
0
 /**
  * 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%/');
 }
コード例 #24
0
ファイル: model.class.php プロジェクト: sujinw/webPHP
 /**
  * [_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;
     }
 }
コード例 #25
0
ファイル: Connection.php プロジェクト: kevinlondon/appfuel
 /**
  * @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;
 }
コード例 #26
0
 /**
  *
  * @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;
 }
コード例 #27
0
ファイル: Connection.php プロジェクト: srayner/zend-db
 /**
  * {@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;
 }
コード例 #28
0
ファイル: Statement.php プロジェクト: srayner/zend-db
 /**
  * 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;
 }
コード例 #29
0
ファイル: db.php プロジェクト: Interghost/university
 /**
  * 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;
 }
コード例 #30
0
 /**
  *
  * @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;
 }