都定义成类了,把这个类拷回去吧,好用得很:
class MyOraDB{
var $Debug = 0;
var $sqoe = 1; // sqoe= show query on error var $Database = "csfdc";
var $User = "csfdc";
var $Password = "1234567"; var $Link_ID = 0;
var $Record = array();
var $Row;
var $Parse;
var $Error = ""; /* public: constructor */
function DB_Sql($query = "") {
$this->query($query);
} function connect() {
if ( 0 == $this->Link_ID ) {
if($this->Debug) {
printf("<br>Connecting to $this->Database...<br>\n");
}
$this->Link_ID=OCIplogon
("$this->User","$this->Password","$this->Database"); if (!$this->Link_ID) {
$this->halt("Link-ID == false " .
"($this->Link_ID), OCILogon failed");
} if($this->Debug) {
printf("<br>Obtained the Link_ID: $this->Link_ID<br>\n");
}
}
} function query($Query_String) { /* No empty queries, please, since PHP4 chokes on them. */
if ($Query_String == "")
/* The empty query string is passed on from the constructor,
* when calling the class without a query, e.g. in situations
* like these: '$db = new DB_Sql_Subclass;'
*/
return 0;
$this->connect(); $this->Parse=OCIParse($this->Link_ID,$Query_String);
if(!$this->Parse) {
$this->Error=OCIError($this->Parse);
} else { OCIExecute($this->Parse);
$this->Error=OCIError($this->Parse);
} $this->Row=0; if($this->Debug) {
printf("Debug: query = %s<br>\n", $Query_String);
} if ($this->Error["code"]!=1403 && $this->Error["code"]!=0 && $this->sqoe)
echo "<BR><FONT color=red><B>".$this->Error["message"]."<BR>Query :\"$Query_String\"</B></FONT>";
return $this->Parse;
} function next_record() {
if(0 == OCIFetchInto($this->Parse,$result,OCI_ASSOC+OCI_RETURN_NULLS)) {
if ($this->Debug) {
printf("<br>ID: %d,Rows: %d<br>\n",
$this->Link_ID,$this->num_rows());
}
$this->Row +=1; $errno=OCIError($this->Parse);
if(1403 == $errno) { # 1043 means no more records found
$this->Error="";
$this->disconnect();
$stat=0;
} else {
$this->Error=OCIError($this->Parse);
if($this->Debug) {
printf("<br>Error: %s",
$this->Error["message"]);
}
$stat=0;
}
} else {
for($ix=1;$ix<=OCINumcols($this->Parse);$ix++) {
$col=strtoupper(OCIColumnname($this->Parse,$ix));
$colreturn=strtolower($col);
$this->Record[ "$colreturn" ] = $result["$col"];
if($this->Debug) echo"<b>[$col]</b>:".$result["$col"]."<br>\n";
}
$stat=1;
} return $stat;
}
function f($Name) {
if (is_object($this->Record[$Name]))
{
return $this->Record[$Name]->load();
} else
{
return $this->Record[$Name];
}
}
}举例说明,就按你的要求读取long字段,假设表名为name,字段名为d_name:
$DB = new MyOraDB;
$sql = select * from name where 条件 order by ......";
$DB -> query($sql);//检查执行sql语句
$DB -> next_record();//指针下移一条
$long = $DB -> f("d_name");//取出long的值为d_name;简单吧,哈哈,
class MyOraDB{
var $Debug = 0;
var $sqoe = 1; // sqoe= show query on error var $Database = "csfdc";
var $User = "csfdc";
var $Password = "1234567"; var $Link_ID = 0;
var $Record = array();
var $Row;
var $Parse;
var $Error = ""; /* public: constructor */
function DB_Sql($query = "") {
$this->query($query);
} function connect() {
if ( 0 == $this->Link_ID ) {
if($this->Debug) {
printf("<br>Connecting to $this->Database...<br>\n");
}
$this->Link_ID=OCIplogon
("$this->User","$this->Password","$this->Database"); if (!$this->Link_ID) {
$this->halt("Link-ID == false " .
"($this->Link_ID), OCILogon failed");
} if($this->Debug) {
printf("<br>Obtained the Link_ID: $this->Link_ID<br>\n");
}
}
} function query($Query_String) { /* No empty queries, please, since PHP4 chokes on them. */
if ($Query_String == "")
/* The empty query string is passed on from the constructor,
* when calling the class without a query, e.g. in situations
* like these: '$db = new DB_Sql_Subclass;'
*/
return 0;
$this->connect(); $this->Parse=OCIParse($this->Link_ID,$Query_String);
if(!$this->Parse) {
$this->Error=OCIError($this->Parse);
} else { OCIExecute($this->Parse);
$this->Error=OCIError($this->Parse);
} $this->Row=0; if($this->Debug) {
printf("Debug: query = %s<br>\n", $Query_String);
} if ($this->Error["code"]!=1403 && $this->Error["code"]!=0 && $this->sqoe)
echo "<BR><FONT color=red><B>".$this->Error["message"]."<BR>Query :\"$Query_String\"</B></FONT>";
return $this->Parse;
} function next_record() {
if(0 == OCIFetchInto($this->Parse,$result,OCI_ASSOC+OCI_RETURN_NULLS)) {
if ($this->Debug) {
printf("<br>ID: %d,Rows: %d<br>\n",
$this->Link_ID,$this->num_rows());
}
$this->Row +=1; $errno=OCIError($this->Parse);
if(1403 == $errno) { # 1043 means no more records found
$this->Error="";
$this->disconnect();
$stat=0;
} else {
$this->Error=OCIError($this->Parse);
if($this->Debug) {
printf("<br>Error: %s",
$this->Error["message"]);
}
$stat=0;
}
} else {
for($ix=1;$ix<=OCINumcols($this->Parse);$ix++) {
$col=strtoupper(OCIColumnname($this->Parse,$ix));
$colreturn=strtolower($col);
$this->Record[ "$colreturn" ] = $result["$col"];
if($this->Debug) echo"<b>[$col]</b>:".$result["$col"]."<br>\n";
}
$stat=1;
} return $stat;
}
function f($Name) {
if (is_object($this->Record[$Name]))
{
return $this->Record[$Name]->load();
} else
{
return $this->Record[$Name];
}
}
}举例说明,就按你的要求读取long字段,假设表名为name,字段名为d_name:
$DB = new MyOraDB;
$sql = select * from name where 条件 order by ......";
$DB -> query($sql);//检查执行sql语句
$DB -> next_record();//指针下移一条
$long = $DB -> f("d_name");//取出long的值为d_name;简单吧,哈哈,
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货