php怎么关闭oracle连接,PHP 连接 Oracle
起因
由于項目的數據庫需要用客戶購買的Oracle數據庫,所以需要php安裝oci擴展。
運行環境
php : 7.2
系統: windows10
oracle: 11gR2
安裝相關環境
由于php的oci8擴展還是需要使用到oracle的一些包,所以先下載這一些。
下載完成后解壓縮這個壓縮包,并且將這個包的路徑添加到PATH中。
下載php的oci8擴展
windows可以直接到這個網址上下載相應的dll,pecl oci8
如果是安裝了pecl的話,可以直接運行 pecl install oci8
下載完成后放到php的ext目錄下,并且編輯php.ini文件,添加extension=php_oci8.dll
這樣就完成了php與oracle的配置了。
在Laravel中使用
Laravel默認支持的數據庫不包含oracle,可以使用 yajra/laravel-oci8這一個包來讓Laravel支持oracle
composer require yajra/laravel-oci8
由于這個包已經支持Laravel的自動加載,也就不需要自己手動去注冊了
"extra": {
"branch-alias": {
"dev-master": "5.6-dev"
},
"laravel": {
"providers": [
"Yajra\\Oci8\\Oci8ServiceProvider"
]
}
},
這樣就可以使用php連接到oracle了。
一個坑
我們在使用migration來管理表格的時候,一般情況下會對每一個表都要有注釋(為了別人能看得懂。。。)。然而這個包有一個bug,就是對于表格的注釋缺少了前綴。
表格的注釋是成員變量而不是方法噢。
/**
* Run the comment on table statement.
* Comment set by $table->comment = 'comment';.
*
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint
*/
private function commentTable(OracleBlueprint $blueprint)
{
$table = $this->wrapValue($blueprint->getTable());
if ($blueprint->comment != null) {
$this->connection->statement("comment on table {$table} is '{$blueprint->comment}'");
}
}
這一段代碼在/vendor/yajar/laravel-oci8/src/Oci8/Schema/Comment.php 中第40行。
這里少了對表前綴的引用,導致我們在migrate的時候生成的sql是缺少了表前綴的,所以在這里添加一個表前綴上去解決這個問題
/**
* Run the comment on table statement.
* Comment set by $table->comment = 'comment';.
*
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint
*/
private function commentTable(OracleBlueprint $blueprint)
{
$table = $this->wrapValue($blueprint->getTable());
if ($blueprint->comment != null) {
$this->connection->statement("comment on table {$this->connection->getTablePrefix()}{$table} is '{$blueprint->comment}'");
}
}
本作品采用《CC 協議》,轉載必須注明作者和本文鏈接
總結
以上是生活随笔為你收集整理的php怎么关闭oracle连接,PHP 连接 Oracle的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 实现的字典序排列算法,字典序的一
- 下一篇: php如何避免时间重复,如何避免/停止p