gpt4 book ai didi

php - 为 codeIgniter ErrorException [8192] : mysql_real_escape_string() 设置数据库

转载 作者:行者123 更新时间:2023-11-30 22:56:23 25 4
gpt4 key购买 nike

我从服务器下载了一个 codeIgniter 项目,并尝试在我的本地主机上运行它,我对 PHP、Mysql 不是很熟悉,我在 stackoverflow 和 google 中使用了不同的建议来设置环境,但仍然有一些错误,如果您能帮助我进行设置,我将不胜感激!

我使用 MAMP 作为本地服务器

这是我的错误:

enter image description here

这是我的database.php

$active_group = ENVIRONMENT;
$active_record = TRUE;

$db['development']['hostname'] = 'mysqli:host=localhost';
$db['development']['username'] = 'root';
$db['development']['password'] = 'pass';
$db['development']['database'] = 'test';
$db['development']['dbdriver'] = 'mysqli';
$db['development']['dbprefix'] = '';
$db['development']['pconnect'] = TRUE;
$db['development']['db_debug'] = FALSE;
$db['development']['cache_on'] = FALSE;
$db['development']['cachedir'] = '';
$db['development']['char_set'] = 'utf8';
$db['development']['dbcollat'] = 'utf8_general_ci';


$db['staging']['hostname'] = 'mysqli:host=localhost';
$db['staging']['username'] = 'mgr';
$db['staging']['password'] = 'test';
$db['staging']['database'] = 'bmg';
$db['staging']['dbdriver'] = 'mysqli';
$db['staging']['dbprefix'] = '';
$db['staging']['pconnect'] = TRUE;
$db['staging']['db_debug'] = FALSE;
$db['staging']['cache_on'] = FALSE;
$db['staging']['cachedir'] = '';
$db['staging']['char_set'] = 'utf8';
$db['staging']['dbcollat'] = 'utf8_general_ci';

这里是mysqli_driver.php

function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}

return $str;
}

if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
elseif (function_exists('mysql_real_escape_string'))
{
$str = mysql_real_escape_string($str);
}
else
{
$str = addslashes($str);
}

if ($like === TRUE)
{
$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}

return $str;
}

感谢任何帮助。

更新

这是扩展列表

; Extensions

;extension=apcu.so

extension=imap.so
extension=yaz.so
extension=mcrypt.so
extension=gettext.so
extension=pgsql.so
extension=pdo_pgsql.so
extension=pdo_mysql.so
I added -> extension=pdo_mysqli.so

;extension=imagick.so
;extension=tidy.so
;extension=oauth.so

我检查了我的 php 信息,我看到 mysqli 启用了

enter image description here

但是在我的文件夹中我没有​​任何mysql.sock

enter image description here

最佳答案

您可以在 CodeIgniter 中更新如下:

    $db = get_instance()->db->conn_id;
$data = json_decode(file_get_contents("php://input"));
$secrectKey = mysqli_real_escape_string($db,$data->secrectKey);

关于php - 为 codeIgniter ErrorException [8192] : mysql_real_escape_string() 设置数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26209269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com