douwei3172 2016-06-23 10:49
浏览 57
已采纳

将Oracle SQL语句的值赋给PHP变量

I am trying to create a PHP page that will run a SQL select statement that returns 1 row and take the values in two of the columns to PHP variables but I am getting the error:

PHP Notice: Undefined index: firstname

Here is what the important part of my code looks like:

$sql = " select * from employee e where e.emp_id = 123";

echo $sql;

$stid = oci_parse($Conn, $sql);
oci_execute($stid);
oci_fetch_all($stid, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW);

var_dump($res);

$firstname = $res['firstname'];

Any idea what can be causing this?

  • 写回答

2条回答 默认 最新

  • douguanyan9928 2016-06-24 05:33
    关注

    Resolved: I had to add [0] after the column:

    $firstname = $res['firstname'][0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?