Codeigniter手动数据库连接

时间:2010-04-28 10:46:54

标签: codeigniter

我在Codeigniter框架中执行php。始终Codeigniter支持默认持久连接。我不想使用该连接。我需要手动连接。它可以在Codeigniter中吗?如果有人知道请帮助我继续前进。我也需要一点解释。

2 个答案:

答案 0 :(得分:2)

如果您不想持久连接,请设置配置文件。

$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";

$config['pconnect'] = FALSE;

$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";

$this->load->database($config);


您可以在http://codeigniter.com/user_guide/database/connecting.html

中阅读更多内容

答案 1 :(得分:0)

您必须更新application / config / databse.php

中的文件

值取决于特定环境。例如,使用SQLite时,您不需要提供用户名或密码,数据库名称将是数据库文件的路径。

如果您使用的是xampp服务器,请将密码字段留空。

$active_group ='default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'test',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);