I have a php script which uploads data to oracle database. When i am running it through my web browser it is working fine. However when i am running it through my command prompt it is giving error : "Fatal error: Uncaught Error: Call to undefined function oci_connect() in C:\wamp64\www\MyLogs\logs2.php:2 Stack trace:
thrown in C:\wamp64\www\MyLogs\logs2.php on line 2"
I checked all the previous queries related to this topic and i set the PATH variable, made changes in php.ini file(extension=php_oci8_12c.dll) and tried below steps to run my script but still no luck.
cd C:\wamp64\bin\php\php7.2.4\ php.exe -f C:\wamp64\www\MyLogs\my_script.php
Can someone please guide what can be possible error. I am attaching my php script.
<?php
$conn = oci_connect('ABC', 'abcABC123', 'abcd1142/AXD');
if (!$conn) {
$m = oci_error();
echo $m['message'], "
";
exit;
}
else {
$d = new DateTime();
$yesterday = $d->sub(new DateInterval('P1D'))->format('Y.m.d');
$filename = "access.$yesterday.txt";
if(file_exists($filename)){
$myfile = fopen($filename, "r");
while(!feof($myfile)) {
$content= fgets($myfile);
$carray=explode(',',$content);
list($IP_ADDRESS, $USER_IDENTIFIER, $USERID , $REQUEST_TIME , $CLIENT_REQUEST ,$RESPONSE_CODE ,$SIZEOFOBJECT, $COOKIES, $AUTHSCHEME, $AUTHMARKET, $X_REQUESTED_WITH, $ENV, $TANUSER)=$carray;
$img=['.gif', '.jpeg', '.png'];
if (strlen(str_replace($img, '', $CLIENT_REQUEST)) !== strlen($CLIENT_REQUEST)) {
// Found an image
continue;
}
$stdii = 'INSERT INTO LOGS(IP_ADDRESS, USER_IDENTIFIER, USERID , REQUEST_TIME , CLIENT_REQUEST ,RESPONSE_CODE ,SIZEOFOBJECT, COOKIES, AUTHSCHEME, AUTHMARKET, X_REQUESTED_WITH, ENV, TANUSER)'.
'values(:IP_ADDRESS, :USER_IDENTIFIER, :USERID , :REQUEST_TIME , :CLIENT_REQUEST ,:RESPONSE_CODE ,:SIZEOFOBJECT, :COOKIES, :AUTHSCHEME, :AUTHMARKET, :X_REQUESTED_WITH, :ENV, :TANUSER)';
$compiled1 = oci_parse($conn, $stdii);
oci_bind_by_name($compiled1, ':IP_ADDRESS', $IP_ADDRESS);
oci_bind_by_name($compiled1, ':USER_IDENTIFIER', $USER_IDENTIFIER);
oci_bind_by_name($compiled1,':USERID', $USERID);
oci_bind_by_name($compiled1, ':REQUEST_TIME', $REQUEST_TIME);
oci_bind_by_name($compiled1, ':CLIENT_REQUEST', $CLIENT_REQUEST);
oci_bind_by_name($compiled1, ':RESPONSE_CODE', $RESPONSE_CODE);
oci_bind_by_name($compiled1, ':SIZEOFOBJECT', $SIZEOFOBJECT);
oci_bind_by_name($compiled1, ':COOKIES', $COOKIES);
oci_bind_by_name($compiled1, ':AUTHSCHEME', $AUTHSCHEME);
oci_bind_by_name($compiled1, ':AUTHMARKET', $AUTHMARKET);
oci_bind_by_name($compiled1, ':X_REQUESTED_WITH', $X_REQUESTED_WITH);
oci_bind_by_name($compiled1, ':ENV', $ENV);
oci_bind_by_name($compiled1, ':TANUSER', $TANUSER);
oci_execute($compiled1, OCI_COMMIT_ON_SUCCESS);
}
//Alert if the file has been uploaded
$message="File Uploaded";
echo "<script type='text/javascript'>alert(\"$message\");</script>";
//closing the file
fclose($myfile);
}
else{
//Alert if the file doesn't exists
$message2="File Doesn't exists";
echo "<script type='text/javascript'>alert(\"$message2\");</script>";
}
}
//Close the database connection
oci_close($conn);
?>
</div>
After struggling with every possible way to resolve my query, i found that are two php.ini files. One is for the command line execution which is located at C:\wamp\bin\php\php5.4.16 , while one is for PHP inside Apache located at C:\wamp\bin\apache\Apache2.4.4\bin. You can check the locations of php.ini files via php -i (for the CLI) and (for the web server). So when you want to run your script through command line you need to make configuration changes in the one located at php folder. Just uncomment or add below line: extension_dir ="c:/wamp64/bin/php/php7.2.4/ext/" extension=php_oci8_12c.dll