Browsing all articles tagged with
Oracle
Oracle简单的带游标的存储过程操作类..
上个帖子发了一个例子..后来为了自己操作方面..封装成了类…只是为了自己方便..所以也共享出来吧..
如果你再改一下..完善一下..充分可以当做一个Oracle操作类的.
- <?php
- /**
- * Punny - The most easy-to-use PHP MVC framework
- * http://punny.skiyo.cn/
- *
- * Copyright (c) 2009 Jessica(董立强)
- * Licensed under the GPL licenses.
- *
- * @author Jessica<cndingo@qq.com>
- * @version $Id$
- */
- class Oracle {
- /**
- *
- * @var <resource> 数据库链接
- */
- private $connect;
- /**
- *
- * @var <resource> SQL语句标识
- */
- private $stmt;
- /**
- * 链接数据库
- *
- * @param <string> $tns
- * @param <string> $user
- * @param <string> $pwd
- */
- public function __construct($tns, $user, $pwd) {
- if(!$this->connect = oci_connect($user,$pwd, $tns)) {
- $this->throwException('链接数据库错误!');
- }
- }
- /**
- * 新建一个游标
- *
- * @return <resource>
- */
- public function addCursor() {
- return oci_new_cursor($this->connect);
- }
- /**
- * 解析一条SQL语句
- *
- * @param <string> $sql
- * @return <resource>
- */
- public function parse($sql) {
- $this->stmt = oci_parse($this->connect, $sql);
- return $this;
- }
- /**
- * 绑定一个参数
- *
- * @param <string> $name
- * @param <mixed> $var
- * @param <int> $length
- * @param <int> $type
- * @return <resource>
- */
- public function bind($name, $var, $length = 10, $type = SQLT_INT) {
- oci_bind_by_name($this->stmt, $name, $var, $length, $type);
- return $this;
- }
- /**
- * 执行一条SQL语句
- *
- * @param <mixed> $stmt
- * @return <resource>
- */
- public function execute($stmt = null) {
- if($stmt) {
- oci_execute($stmt);
- } else {
- oci_execute($this->stmt);
- }
- return $this;
- }
- /**
- * 获取结果集
- *
- * @param <mixed> $stmt
- * @return <array>
- */
- public function getAll($stmt = null) {
- if($stmt) {
- while ($row = oci_fetch_array ($stmt, OCI_ASSOC)) {
- $rows[] = $row;
- }
- } else {
- while ($row = oci_fetch_array ($this->stmt, OCI_ASSOC)) {
- $rows[] = $row;
- }
- }
- return $rows;
- }
- /**
- * 抛出一个异常信息
- *
- * @param string $message
- */
- protected function throwException($message) {
- throw new Exception($message);
- }
- }
- ?>
使用例子:(最下面有下载)
如何在Oracle中获取有游标的存储过程的结果集.
在工作中遇到的..网上查了写的也不详细..再此做下笔记.
- $tns = "
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = cnc)
- )
- )
- ";
- $db_username = "test";
- $db_password = "test";
- $conn = oci_connect($db_username,$db_password, $tns);
- $id = 1;
- //创建一个游标
- $cur = oci_new_cursor($conn);
- $sql = "begin packname.someproceduce( :id, :cousor); end;";
- $stmt = oci_parse($conn,$sql);
- oci_bind_by_name($stmt,":id",$id);
- //绑定cursor变量,注意$sql语句中:cursor变量的位置
- oci_bind_by_name($stmt,":cousor",$cur,-1,OCI_B_CURSOR);
- oci_execute($stmt);
- oci_execute($cur);
- while ($row = oci_fetch_array ($cur, OCI_ASSOC)) {
- print_r($row);
- }
分类目录
- ActionScript (2)
- CSS (25)
- Java (3)
- JavaScript (41)
- PHP (108)
- 心情杂谈 (34)
- 收集整理 (77)
- 本站原创 (58)
最近文章
- [演讲稿]OAuth1.0协议
- 在sae中利用SaeFetchurl进行豆瓣的OAuth授权
- OAuth 1.0a与1.0协议的改进…
- 深入理解OAuth与豆瓣OAuth test
- include_path+__autoload与数组+__autoload的比较
- 将google ssl设置为IE8的默认搜索引擎..
- 我们来做一个会呼吸的菜单吧!!
- 在编译php-fpm0.6的时候需要注意的一些问题
- 使用PHP将大文件导入到数据库中..
- 关于用PHP调用WebService中参数为complexType的问题
- 神奇的两次按位非运算符
- 百路推免费短网址服务..首创”收藏夹获取短网址”..
- 哥学社正式上线..
- jQuery中getJSON跨域原理详解
- Web辅助工具条(原名:河蟹工具条CrabBar)0.1发布
近期评论
- Gonten 在 在sae中利用SaeFetchurl进行豆瓣的OAuth授权 上的评论
- Amaranth 在 [演讲稿]OAuth1.0协议 上的评论
- 胖子 在 [演讲稿]OAuth1.0协议 上的评论
- 老飞的小窝 在 jQuery中getJSON跨域原理详解 上的评论
- Jackie.Hamos 在 将google ssl设置为IE8的默认搜索引擎.. 上的评论
- Elmer Zhang 在 在sae中利用SaeFetchurl进行豆瓣的OAuth授权 上的评论
- 茶叶蛋 在 一个PHP+AJAX留言板的完整例子.非常简单! 上的评论
- 9527 在 我们为什么要抛弃模板引擎?? 上的评论
- hikurasai 在 Flash TagCloud中文版. 上的评论
- lx 在 PHP上传进度条深度解析 上的评论
文章归档
- 2010 年九月 (1)
- 2010 年八月 (4)
- 2010 年七月 (3)
- 2010 年六月 (4)
- 2010 年五月 (2)
- 2010 年四月 (9)
- 2010 年三月 (12)
- 2010 年二月 (1)
- 2010 年一月 (3)
- 2009 年十二月 (2)
- 2009 年十一月 (3)
- 2009 年十月 (3)
- 2009 年九月 (5)
- 2009 年八月 (4)
- 2009 年七月 (6)
- 2009 年六月 (8)
- 2009 年五月 (8)
- 2009 年四月 (16)
- 2009 年三月 (19)
- 2009 年二月 (22)
- 2009 年一月 (20)
- 2008 年十二月 (38)
- 2008 年十一月 (22)
- 2008 年十月 (7)
- 2008 年九月 (3)
- 2008 年八月 (24)
标签
.net
AJAX
button
Comet
CSS
Discuz!
DIV+CSS
Flash
Form
Google
HTML编辑器
IE8
Java
JavaScript
jQuery
JSP
md5
MySQLReback
OAuth
Oracle
PHP
php-fpm
PNG
Punny
SkiyoTabs
tab
TagCloud
Vista
Web2.0
Windows7
上传
加密
图标
本站原创
模板
模板引擎
源码
登录
短网址
石家庄
算法
类
编译
面向对象
魔术方法

Jessica
