经测试代码如下:
/**
* 使用CodeIgniter检查数据库连接
*
* @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
* @arrange (512.笔记) jb51.cc
**/
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;
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528908.html