此文章同步刊登於我的部落格
環境建置
一、安裝Oracle Instant Client
- 到此網頁下載「Basic Packge」
- 解壓縮到資料夾
- 新增環境變數
C:\instantclient_21_3
二、安裝PHP擴展
- 將「php_oci8_12c.dll」放入
/php/ext/12c
代表Oracle版本 - 將php.ini中的「;extension=oci8_12c」註解取消
- 重新啟動Apache或其他Web Server以重新載入php.ini的設定
PHP串接
一、 連線設定
$host = '[SERVER_HOST]';
$port = '[SERVER_PORT]';
$service_name = '[SERVICE_NAME]';
$username = '[ACCOUNT]';
$password = '[PASSWORD]';
$config = array(
'hostname' => "$host:$port/$service_name",
'username' => $user,
'password' => $password,
'database' => '',
'dbdriver' => 'oci8',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => $this->char_set,
'dbcollat' => $this->dbcollat,
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => $this->save_queries
);
try {
$db = @$this->load->database($config, true);
if(empty($db->conn_id)) {
echo $db->error()['message'];
} else {
}
} catch (Exception $e) {
echo $e->getMessage();
}
環境
- Windows 10
- Wamp Server 3.2.3
- PHP 7.4.9
- CodeIgniter 3.1.16
- Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Productioninstantclient_21_3