php实现oracle操作
时间:2021-07-01 10:21:17
帮助过:2人阅读
function Query(
$sql,
$prms){
$db = " (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = XXX)(PORT = 1521)) (CONNECT_DATA = (SID=orcl) (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )"
;
$db_uname = "xxx"
;
$db_upass = "XXXXXX"
;
$conn = oci_connect(
$db_uname,
$db_upass,
$db);
$stmt = oci_parse(
$conn,
$sql);
if(
is_array(
$prms)){
foreach (
$prms as $key =>
$val){
oci_bind_by_name($stmt,
$key,
$val);
}
}
oci_execute($stmt,
OCI_DEFAULT);
$rownum = oci_fetch_all(
$stmt,
$result);
oci_free_statement($stmt);
oci_close($conn);
return $result;
}
function BeginTran(){
$db = " (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = XXX)(PORT = 1521)) (CONNECT_DATA = (SID=orcl) (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )"
;
$db_uname = "xxx"
;
$db_upass = "xxx"
;
$conn = oci_connect(
$db_uname,
$db_upass,
$db);
return $conn;
}
function CloseConn(
$conn){
oci_close($conn);
}
function Commit(
$conn){
oci_commit($conn);
CloseConn($conn);
}
function RollBack(
$conn){
oci_rollback($conn);
CloseConn($conn);
}
?>
<?php
require ‘db.php‘;
// $res = Query("select * from customerinfo where rownum < 100", null);
// for($i = 0;$i< 99;$i++){
// foreach ($res as $data){
// echo $data[$i];
// }
// }
$sql = "insert into hostparam (paramtype,paramvalue) values (:ptype,:pval)";
$conn = BeginTran();
$num = 0;
try {
$stmt = oci_parse($conn, $sql);
$ptype = "1";
$pval = "2";
oci_bind_by_name($stmt, ":ptype", $ptype);
oci_bind_by_name($stmt, ":pval", $pval);
oci_execute($stmt,OCI_DEFAULT);
$num = oci_num_rows($stmt);
Commit($conn);
} catch (Exception $e) {
RollBack($conn);
}
echo $num;
?>
php实现oracle操作
标签: