PHP 检查数据库连接详细信息 - CodeIgniter

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 检查数据库连接详细信息 - CodeIgniter相关的知识,希望对你有一定的参考价值。

/**
 * Check Database Connection
 * 
 * Checks connection details to see if they are correct. Useful for testing
 * user supplied details in an install controller.
 * 
 * @access	protected
 * @param	string		$protocol	protocol to connect with
 * @param	string		$host		host to connect to
 * @param	string		$user		username to login with
 * @param	string		$pass		password to login with
 * @param	string		$database	database to check for
 * @param	integer		$port		port to connect on (optional)
 * @return	bool
 */
protected function _check_db($protocol,$host,$user,$password,$database,$port = NULL)
{
	// prep the DSN string
	$dsn = "{$protocol}://{$user}:{$password}@{$host}/{$database}";
	if($port !== NULL)
	{
		$dsn .="?port={$port}";
	}

	// Load the database and dbutil
	$this->load->database($dsn);
	$this->load->dbutil();

	// check the connection details
	$check = $this->dbutil->database_exists($database);

	// close the database
	$this->db->close();

	// return our status
	return $check;
}

以上是关于PHP 检查数据库连接详细信息 - CodeIgniter的主要内容,如果未能解决你的问题,请参考以下文章