douwei3172 2016-06-23 18: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 13:33
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题