亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Array Array Helper Benchmarking Benchmarking Class Caching Caching Driver Calendaring Calendaring Class CAPTCHA CAPTCHA Helper Config Config Class Cookie Cookie Helper Database Connecting to your Database Custom Function Calls Database Caching Class Database Configuration Database Forge Class Database Metadata Database Quick Start: Example Code Database Reference Database Utility Class DB Driver Reference Generating Query Results Queries Query Builder Class Query Helper Methods Transactions Date Date Helper Directory Directory Helper Download Download Helper Email Email Class Email Helper Encrypt Encrypt Class Encryption Encryption Library File File Helper File Uploading File Uploading Class Form Form Helper Form Validation Form Validation FTP FTP Class Functions compatibility_functions common_functions HTML HTML Helper HTML Table HTML Table Class Image Manipulation Image Manipulation Class Inflector Inflector Helper Input Input Class Javascript Javascript Class Language Language Class Language Helper Loader Loader Class Migrations Migrations Class Number Number Helper Output Output Class Pagination Pagination Class Path Path Helper Security Security Class Security Helper Session Session Library Shopping Cart Shopping Cart Class Smiley Smiley Helper String String Helper Template Parser Template Parser Class Text Text Helper Trackback Trackback Class Typography Typography Class Typography Helper Unit Testing Unit Testing Class URI URL User Agent XML XML-RPC and XML-RPC Server Zip Encoding Zip Encoding Class XML-RPC and XML-RPC Server Classes XML Helper User Agent Class URL Helper URI Class
characters

有兩種連接數(shù)據(jù)庫的方法:

自動連接

“自動連接”功能將在每次加載頁面時加載和實例化數(shù)據(jù)庫類。要啟用“自動連接”,請將Word數(shù)據(jù)庫添加到庫數(shù)組中,如下文件所示:

application/config/autooload.php

手動連接

如果只有某些頁面需要數(shù)據(jù)庫連接,則可以通過在需要的任何函數(shù)中添加這一行代碼或在類構(gòu)造函數(shù)中手動連接到數(shù)據(jù)庫,從而使數(shù)據(jù)庫在該類中全局可用。

$this->load->database();

如果上面的函數(shù)在第一個參數(shù)中包含任何信息,它將連接到數(shù)據(jù)庫配置文件中指定的組。對于大多數(shù)人來說,這是首選的使用方法。

可用參數(shù)

  • 數(shù)據(jù)庫連接值,作為數(shù)組或DSN字符串傳遞。

  • TRUE / FALSE(布爾值)。是否返回連接ID(請參閱下面的連接到多個數(shù)據(jù)庫)。

  • TRUE / FALSE(布爾值)。是否啟用查詢生成器類。默認設(shè)置為TRUE。

手動連接到數(shù)據(jù)庫

此函數(shù)的第一個參數(shù)可以任選用于從配置文件中指定特定的數(shù)據(jù)庫組,或者甚至可以為配置文件中未指定的數(shù)據(jù)庫提交連接值。例子:

要從配置文件中選擇特定的組,可以這樣做:

$this->load->database('group_name');

所在群[醫(yī)]名稱是配置文件中連接組的名稱。

要手動連接到所需的數(shù)據(jù)庫,可以傳遞一個值數(shù)組:

$config['hostname'] = 'localhost';
$config['username'] = 'myusername';
$config['password'] = 'mypassword';
$config['database'] = 'mydatabase';
$config['dbdriver'] = 'mysqli';
$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);

有關(guān)這些值中每個值的信息,請參見配置頁...

對于PDO驅(qū)動程序,應該使用$config‘dsnn’設(shè)置而不是“主機名”和“數(shù)據(jù)庫”:

也可以將數(shù)據(jù)庫值作為數(shù)據(jù)源名稱提交。DSNS必須具有以下原型:

$dsn = 'dbdriver://username:[email protected]/database';$this->load->database($dsn);

若要在與DSN字符串連接時重寫默認配置值,請將配置變量添加為查詢字符串。

$dsn = 'dbdriver:
//username:[email protected]/database?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=/path/to/cache';
$this->load->database($dsn);

連接到多個數(shù)據(jù)庫

如果你需要同時連接多個數(shù)據(jù)庫,你可以這樣做:

$DB1 = $this->load->database('group_one', TRUE);$DB2 = $this->load->database('group_two', TRUE);
  • 注意:將單詞“group_one”和“group_two”更改為要連接的特定組名(或者您可以按照上面所述傳遞連接值)。

通過將第二個參數(shù)設(shè)置為TRUE(布爾值),該函數(shù)將返回數(shù)據(jù)庫對象。

以這種方式連接時,您將使用對象名稱來發(fā)布命令,而不是本指南中使用的語法。換句話說,而不是發(fā)出命令:

如果只需要在同一連接上使用不同的數(shù)據(jù)庫,則不需要創(chuàng)建單獨的數(shù)據(jù)庫配置。您可以在需要時切換到不同的數(shù)據(jù)庫,如下所示:

重新連接/保持連接正常

如果數(shù)據(jù)庫服務(wù)器的空閑超時在您執(zhí)行一些繁重的PHP提升(例如處理圖像)時被超過,則應該考慮在發(fā)送進一步查詢之前使用reconnect()方法對服務(wù)器執(zhí)行ping操作,這可以適當?shù)乇3诌B接活著或重新建立它。

$this->db->reconnect();

手動關(guān)閉連接

雖然CodeIgniter智能地負責關(guān)閉數(shù)據(jù)庫連接,但您可以顯式關(guān)閉連接。

$this->db->close();
Previous article: Next article: