gpt4 book ai didi

php - CodeIgniter:无法使用提供的设置连接到数据库服务器错误消息

转载 作者:行者123 更新时间:2023-11-29 16:02:13 26 4
gpt4 key购买 nike

我一直使用 CI,使用 MySQL 驱动程序,效果很好。我想使用 MySQL 驱动程序,但是一旦我更改它(只需在 MySQL 末尾添加“i”,并添加端口号),我就会收到以下错误消息

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 232

我的设置如下:

$db['default']['hostname'] = $hostname;
$db['default']['username'] = $username;
$db['default']['password'] = $password;
$db['default']['database'] = $database;
$db['default']['dbdriver'] = 'mysqli';
$db['default']['port'] = "3306";
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

where
$hostname = 'localhost';
$username = 'myusernamegoeshere';
$password = 'mypasswordgoeshere';
$database = 'mydatabasenamegoeshere';

我正在使用:

CI 2.0.2 php 5.3.4 Apache/2.2.17 (Unix) mysql 5.5.13 mysql.default_port 3306

我做错了什么吗?

谢谢,

最佳答案

我认为 PHP 配置有问题。
首先,使用 ./config/database.php 末尾的脚本调试数据库连接:

...
...
...
echo '<pre>';
print_r($db['default']);
echo '</pre>';

echo 'Connecting to database: ' .$db['default']['database'];
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['default']['database']);

echo '<br /> Connected OK:' ;
die( 'file: ' .__FILE__ . ' Line: ' .__LINE__);

然后看看问题是什么。

关于php - CodeIgniter:无法使用提供的设置连接到数据库服务器错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56093781/

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