如何在 PHP 原生查询中使用 mysqli 驱动程序?
How can I use mysqli drivers in PHP native query?
例如.我的代码:
型号
class Home_model extends CI_Model{
public function getusers(){
$q = "SELECT * FROM `users`";
return $r = mysqli_query($q);
}
}
控制器:
class Home extends CI_Controller{
public function iterateuser(){
while($row = mysqli_fetch_object($this->Home_model->getusers())) {
echo $row->username;
}
}
我上面的代码有一个错误,说:
My code above has an error, saying:
mysqli_query 需要至少 2 个参数
mysqli_query expects at least 2 parameters
CodeIgniter 中是否有一种方法可以传递 mysqli_query()
第一个参数上的链接,如 php.net 文档中所述http://php.net/manual/en/mysqli.query.php
Is there a way in CodeIgniter to pass the link on the mysqli_query()
first parameter as described on the php.net documentation http://php.net/manual/en/mysqli.query.php
转到:
yourproject/application/config/database.php
变化:
$db['default']['dbdriver'] = 'mysql';
与:
$db['default']['dbdriver'] = 'mysqli';
这篇关于如何在 CodeIgniter 中使用 MySQLi 驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!