phporacle-databaseoracle12cexecuteoci8

oci_parse(): and oci_execute(); warnings


Started using oci_ functions in PHP. Running into the subject error.

My database file is as follows:

<?php 
  $conn = oci_connect("user", "pass", "LOSINGMINDHOST");
  if (!$conn) {
     $e = oci_error();
     error_log(trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR));
  }

  oci_close($conn);
?>

Confirmed the above connection string is successful.

Now, in my test file, I have the following:

<?php
  include("include/database.php");

  $queryMain = oci_parse($conn, "select * from sometable");

  oci_execute($queryMain);
?>

Using the above, here is what I am getting on screen:

Warning: oci_parse(): supplied resource is not a valid oci8 connection resource in D:\htdocs\mysite\test.php on line 4
Warning: oci_execute() expects parameter 1 to be resource, bool given in D:\htdocs\mysite\test.php on line 26

I am using PHP 7.4 on a Windows Server 2019.

I checked the php.ini file to make sure the oci8 connections are available and/or uncommented out.

What else do I need to make this work?


Solution

  • Immediately after you open the connection you close it again. This makes it unusable. Remove the oci_close($conn); call.

    Overall, you might want to look at a different architecture, such as using classes.