2010-04-28 63 views
1

我在做Codeigniter框架中的php.Always Codeigniter支持默认持久连接。我不想使用该连接。我需要手动连接。它可能在Codeigniter中吗?如果有人知道请帮助我前进,我也需要一点解释。Codeigniter手册数据库连接

回答

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

+0

so ** pconnect **支持持续连接 – 2017-07-26 11:04:43

0

您有/配置/ 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 
);