• php实现oracle操作


    <?php
    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;
    ?>
  • 相关阅读:
    openCR-用ROS代码获取电压的方法
    openCR-用ROS代码控制按键的方法
    TurtleBot3-基础例程
    TurtleBot3-键盘远程控制
    TurtleBot3-Topic Monitor
    openCR-串口打印HelloWorld
    Ubuntu播放音乐 mp3 wav
    SQL Server2008创建约束图解 转
    height、clientHeight、scrollHeight、offsetHeight区别
    第一次弄项目有感
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/4670839.html
Copyright © 2020-2023  润新知