Oracle数据库php短连接,PHP 连接 Oracle

起因

由于项目的数据库需要用客户购买的Oracle数据库,所以需要php安装oci扩展。

运行环境

php : 7.2

系统: windows10

oracle: 11gR2

安装相关环境

由于php的oci8扩展还是需要使用到oracle的一些包,所以先下载这一些。

1d72a9cc2058d725efd6b2eec5321899.png

下载完成后解压缩这个压缩包,并且将这个包的路径添加到PATH中。

bbc9cd8fd23920aac4c529a584d296e2.png

下载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 协议》,转载必须注明作者和本文链接

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值