PHP 連線oracle

nintyuui發表於2021-09-09

  1. 安裝oracle Client

    oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

    oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

    下載地址:

    rpm -ivh oracle-install*

    此時生成目錄:/usr/lib/oracle/11.2/client64/lib

    在/etc/ld.so.conf 追加一下內容:

    /usr/lib/oracle/11.2/client64/lib

    執行命令:ldconfig

  2. 安裝OCI8

    下載地址:

    /usr/bin/phpize (用phpize生成configure配置檔案)

    ./configure --with-php-config=/usr/bin/php-config --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib

    make && make install

    注:phpize安裝:yum install php-devel

  3. 連線oracle


    $conn = oci_connect('user,'password','ip:port/sid');


    $sql = "select  count(*) from test";

    $sth = oci_parse($conn,$sql);

    oci_execute($sth,OCI_DEFAULT);

    while($r=oci_fetch_row($sth))

    {

    echo $r[0];

    }


    ?>

  4. 問題處理:

    Oracle 11G特殊問題:

    初次連線時,提示

    ORA-24408: could not generate unique server group name

    解決:

    more /etc/sysconfig/network

    檢視 HOSTNAME

    vi /etc/hosts

    127.0.0.1 HOSTNAME

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/3209/viewspace-2802230/,如需轉載,請註明出處,否則將追究法律責任。

相關文章