Hy! I have a problem with printing query results. I thought it will work with a simple echo statement, but it does not. When I run the following code: if ($c = @oci_connect("username","password","xe")) { $s = oci_parse($c,"SELECT '$text' FROM text_web where ID = '1'"); oci_execute($s,OCI_DEFAULT); echo $s; } Code (markup): As result I get: Resource id #2 May somebody tell me where I went wrong here! Thanks for help! steyr
The variable '$s' would store the statement resource, which is why you get "Resource ID #n" when you try to print it out. To get the actual row/data, you'll want to use one of the "oci_fetch_*" functions. For example: oci_execute($s, OCI_DEFAULT); $row = oci_fetch_array($s); echo $row['field']; PHP: Where 'field' is the name of the table field you're trying to output. "oci_fetch_array" returns both numeric and associative arrays. There's also "oci_fetch_object" and others, to return the data in different formats.
Hy! Thanks for reply! I tried what you posted and some other variants and I always got stuck at with the same error massage: Notice: Undefined index: english in C:\Programme\Zend\Apache2\htdocs\test.php on line 34 what defines the table field is in my case a variable! here is an example if($language == 'en'){ $text = 'english'; } else if ($language == 'de') { $text= 'german'; } if ($c = @oci_connect("username","password","xe")) { $s = oci_parse($c,"SELECT '$text' FROM text_web WHERE ID = '1'"); oci_execute($s,OCI_DEFAULT); oci_execute($s, OCI_DEFAULT); $row = oci_fetch_array($s); echo $row[$text]; } Code (markup):
The second "oci_execute" you have is unneeded. Additionally, you may want to change your query, to "SELECT $test" or "SELECT {$test}" instead. Your edited code: if($language == 'en'){ $text = 'english'; } else if ($language == 'de') { $text= 'german'; } if ($c = @oci_connect("username","password","xe")) { $s = oci_parse($c,"SELECT {$text} FROM text_web WHERE ID = '1'"); oci_execute($s, OCI_DEFAULT); $row = oci_fetch_array($s); echo $row[$text]; } PHP: Try that, and if it doesn't work, change "echo $row[$text];" to "var_dump($row);" and post the results.
Hello! Thanks for help!!! I tried as you posted, but the result is still the same. When I use "var_dump($row);" I get the correct result but in the array form: array(2) { [0]=> string(14) "this is a test" ["ENGLISH"]=> string(14) "this is a test" }
Note that higher-end databases like Oracle will uppercase all field names when returning results. Unfortunately I don't work with these database servers very often. If you want to continue using the field names in $text, I'd recommend changing your initial "if" statements to look as such: if ($language == 'en') { $text = 'ENGLISH'; } elseif ($language == 'de') { $text= 'GERMAN'; } PHP: Otherwise, as you can see from the array, you can also access your desired result using "$row[0]" instead of "$row[$text]", since you have only one field being returned.