我刚刚解决了这个问题。我还需要在oracle 11 g中使用BLOB,我想将图像插入oracle表中。 我在网上到处搜索,最后我在enter link description here找到了一个可能的解决方案。 请点击退出。 我遵循示例2
<?php
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
$stmt = $db->prepare("insert into images (id, contenttype, imagedata) values (?, ?, ?)");
$id = get_new_id(); // some function to allocate a new ID
// assume that we are running as part of a file upload form
// You can find more information in the PHP documentation
$fp = fopen($_FILES['file']['tmp_name'], 'rb');
$stmt->bindParam(1, $id);
$stmt->bindParam(2, $_FILES['file']['type']);
$stmt->bindParam(3, $fp, PDO::PARAM_LOB);
$db->beginTransaction();
$stmt->execute();
$db->commit();
?>
我通过以下方式获取$db
$db = Yii::app()->db->getPdoInstance()
而是通过
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
4条答案
按热度按时间r7s23pms1#
Yii的ActiveRecord模型中有beforeSave()和afterSave()事件方法。我会使用这些方法来代替save()方法。把所有必要的Oracle方法都放在那里。基本上:将beforeSave()中的字段清空,然后在afterSave()中使用OCIParse()将值写入DB,等等。
这里有一篇关于使用Cake PHP框架的博客文章,它非常类似(MVC,带有before和after保存方法)。显然,你需要修改这段代码来使用Yii,但它应该会让你走上正确的道路:
http://nik.chankov.net/2008/01/03/cakephp-and-oracle-handling-clob-fields/
最新版本的Yii现在也有一个查询生成器,它可能会对你需要编写的afterSave()代码有所帮助:
http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder
祝你好运!
aurhwmvo2#
我刚刚解决了这个问题。我还需要在oracle 11 g中使用BLOB,我想将图像插入oracle表中。
我在网上到处搜索,最后我在enter link description here找到了一个可能的解决方案。
请点击退出。
我遵循示例2
我通过以下方式获取$db
而是通过
和其他事情都是一样的。
祝你好运!
wooyq4lh3#
这对我很有效,但我几乎没有什么赞扬,我正在开始将MySQL改编为ORACLE。疯狂!!!
这是一个测试版,如果能改进它会有帮助。
覆盖模型中的__get函数。
.......................................................................................................................................................................................................
}
92vpleto4#
我们的项目在使用yii2和Oracle数据库时也遇到了阅读和写入LOB字段的问题。因此,目前,我决定写一个类来覆盖yii2中ActiveRecord类的一些方法,并继承一些模型,而不是从ActiveRecord继承。我使它相对通用,你可以把它作为你改进https://github.com/pivasikkost/yii2-improvements/blob/master/models/ActiveRecordOciLob.php的基础。