V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
rmtjp
V2EX  ›  问与答

PHP 连接 oracle 数据库并查询

  •  
  •   rmtjp · 2014-06-23 01:52:38 +08:00 · 5373 次点击
    这是一个创建于 3594 天前的主题,其中的信息可能已经有所发展或是发生改变。
    “host”=> "web",
    "user" => "www",
    "passwd" => "2014"
    配置如上,求一个php脚本,连接并进行管理.
    非程序员,不懂PHp,万分感谢~
    6 条回复    2014-07-10 15:16:20 +08:00
    Sunyanzi
        1
    Sunyanzi  
       2014-06-23 02:47:06 +08:00 via Android
    需求說的不清不楚的 ... 不懂 php 至少要看下吧 ...

    我猜 ... 這個大概能幫到你 http://php.net/oci_connect ...
    rmtjp
        2
    rmtjp  
    OP
       2014-06-23 02:50:09 +08:00
    @Sunyanzi 嗯,之前有看,环境的话是osx连局域网内的另外一台机器
    这个需要有‘SID’我从服务器上没有看到这个...
    raincious
        3
    raincious  
       2014-06-23 08:01:59 +08:00 via Android
    smblog
        4
    smblog  
       2014-06-23 08:09:16 +08:00
    没 SID 就这样配置

    $hostname = 'localhost';
    $username = 'user';
    $password = 'pass';
    $database = 'db';

    $datastr = "(description=(address=(protocol=tcp)
    (host=".$hostname.")(port=1521))
    (connect_data=(service_name=".$database.")))";

    if(!$link = oci_connect($username,$password,$datastr)) {
    die('Can not connect to Oracle server');
    }

    $sql = "select * from uset_tabs";
    $result = oci_parse($link,$sql);
    oci_execute($result);
    $res = oci_fetch_array($result, OCI_ASSOC);
    print_r($res);
    zencoding
        5
    zencoding  
       2014-06-23 09:03:42 +08:00
    @rmtjp 最佳解决方案 https://github.com/catfan/Medoo 不谢
    zhanglp888
        6
    zhanglp888  
       2014-07-10 15:16:20 +08:00
    <?php
    $c = oci_connect('用户名', '密码', '地址/sid','UTF8');
    if (!$c) {
    $m = oci_error();
    trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
    }
    $s = oci_parse($c, "SELECT * FROM employees");
    if (!$s) {
    $m = oci_error($c);
    trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);
    }
    $r = oci_execute($s);
    if (!$r) {
    $m = oci_error($s);
    trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);
    }
    $r = oci_fetch_all($s, $res);
    if (!$r) {
    $m = oci_error($s);
    trigger_error('Could not fetch rows: '. $m['message'], E_USER_ERROR);
    }
    echo "<table border='1'>\n";
    foreach ($res as $row) {
    echo "<tr>\n";
    foreach ($row as $item) {
    echo " <td>".($item!==null?htmlentities($item, ENT_QUOTES):"&nbsp;")."</td>\n";
    }
    echo "</tr>\n";
    }
    echo "</table>\n";
    ?>
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5960 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:17 · PVG 10:17 · LAX 19:17 · JFK 22:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.