1

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?

7
  • This doesn't look like it would return just one row. What does the var_dump($res); give you? Commented Jun 23, 2016 at 18:52
  • Hi @digitalChris - this will return just one row, I forgot the where clause in the original post Commented Jun 23, 2016 at 18:53
  • I suspect Oracle would return column names in uppercase. Try $res['FIRSTNAME'] Commented Jun 23, 2016 at 18:55
  • Look at the syntax for oci_fetch_all What happens when you var_dump($res)? Commented Jun 23, 2016 at 18:56
  • I get back a two dimensional array? Commented Jun 23, 2016 at 18:59

2 Answers 2

1

Check by this code

$firstname = $res[0]['firstname'];
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - this was VERY close
0

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

$firstname = $res['firstname'][0];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.