php 使用CodeIgniter检查数据库连接是否正确的解决办法
内容摘要
这篇文章主要为大家详细介绍了php 使用CodeIgniter检查数据库连接是否正确的简单示例,具有一定的参考价值,可以用来参考一下。
php使用CodeIgniter检查数据库连接是否正确,对
php使用CodeIgniter检查数据库连接是否正确,对
文章正文
这篇文章主要为大家详细介绍了php 使用CodeIgniter检查数据库连接是否正确的简单示例,具有一定的参考价值,可以用来参考一下。
php使用CodeIgniter检查数据库连接是否正确,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <code class = "php" > /** * 使用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 (www.idcnote.com) **/ 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教程(www.idcnote.com) ***/ </code> |
注:关于php 使用CodeIgniter检查数据库连接是否正确的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释