• php 连接oracle


    https://blog.csdn.net/qq_34221812/article/details/85269781

    https://www.cnblogs.com/semonxv/p/3831573.html

    解决乱码问题:

    连接时 设置编码:$conn = oci_connect("C##SCOTT", "tiger",$db,'utf8');

    绑定数据时候中文转码:mb_covert_encoding($data,'GBK','UTF-8');

    plsql 操作数据库:

    select * from user_constraints where table_name='表名字,必须大写';                    //通过sql去查询这个表的约束

    select userenv('language') from dual;                         //查看字符集

    sql语句select * from V$NLS_PARAMETERS查看本地字符集,查看第一行和第九行是否对应

    oci 操作 oracle 数据库:

    public function select(){
    //echo phpinfo();die();
    $conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');

    if($conn){
    echo "connect success";
    echo '<br>';
    }else{
    echo "connect error";
    echo '<br>';
    }
    $sql = "select * from or_student";
    $ora_test = oci_parse($conn,$sql); //编译sql语句
    oci_execute($ora_test,OCI_COMMIT_ON_SUCCESS); //执行

    //1、第一种
    $rr = oci_fetch_all($ora_test,$r);

    //2、第二种
    //$r = oci_fetch_array($ora_test, OCI_BOTH);

    foreach($r as $rows){
    echo "";echo '<br>';
    foreach($rows as $col_values){
    echo $col_values.'/';
    }
    }
    echo '<br>';echo '<br>';
    var_dump($r);
    //var_dump($rr);

    //释放资源
    oci_free_statement($ora_test);
    oci_close($conn);
    }

    public function add1(){
    $conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');
    $query="insert into or_student(S_ID,S_NAME,S_SEX) values(:S_ID,:S_NAME,:S_SEX)";
    $statement=oci_parse($conn,$query);

    $S_ID='8';
    $S_NAME='qq';
    $S_SEX='';

    oci_bind_by_name($statement,":s_id",$S_ID);
    oci_bind_by_name($statement,":s_name",$S_NAME);
    oci_bind_by_name($statement,":s_sex",$S_SEX);



    //执行语句,设置执行模式为自动提交
    oci_execute($statement,OCI_COMMIT_ON_SUCCESS);
    //检查影响的行数

    echo "插入成功:".oci_num_rows($statement);


    //释放资源
    oci_free_statement($statement);
    oci_close($conn);

    }

    public function add2(){
    $conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');
    $query="insert into or_student(s_id,s_name,s_sex) values(9,'第七','')";
    $statement=oci_parse($conn,$query);

    //执行语句,设置执行模式为自动提交
    oci_execute($statement,OCI_COMMIT_ON_SUCCESS);
    //检查影响的行数

    echo "插入成功:".oci_num_rows($statement);

    //释放资源
    oci_free_statement($statement);
    oci_close($conn);

    }



    public function delete(){

    $conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');
    $query="delete from or_student where S_ID=5";
    $statement=oci_parse($conn,$query);


    //执行语句,设置执行模式为自动提交
    oci_execute($statement,OCI_COMMIT_ON_SUCCESS);
    //检查影响的行数

    echo "删除成功:".oci_num_rows($statement);


    //释放资源
    oci_free_statement($statement);
    oci_close($conn);


    }
  • 相关阅读:
    Centos5.x 更换yum源
    前端常用的数据处理(基础版)
    动态库和静态库的区别是什么(转)
    java8.0_181b13 异常信息
    sql server 跨数据库调用存储过程
    基于51单片机的简易“视频播放器”
    https还安全吗 https抓包原理 https抓包工具
    hash 碰撞的2种解决办法
    商品秒杀提高QPS解决方案
    指针压缩原理和为什么指针压缩只能压缩3位
  • 原文地址:https://www.cnblogs.com/isungge/p/10955974.html
Copyright © 2020-2023  润新知