我有一个php脚本,可将数据上传到oracle数据库。当我通过Web浏览器运行它时,它工作正常。但是,当我通过命令提示符运行它时,出现错误:“致命错误:未捕获的错误:调用C:\ wamp64 \ www \ MyLogs \ logs2.php:2中未定义的函数oci_connect() 堆栈跟踪:
在第2行的C:\ wamp64 \ www \ MyLogs \ logs2.php中抛出”
我检查了与该主题相关的所有先前查询,并设置了PATH变量,对php.ini文件(extension = php_oci8_12c.dll)进行了更改,并尝试了以下步骤来运行我的脚本,但仍然没有运气。 >
cd C:\ wamp64 \ bin \ php \ php7.2.4 \ php.exe -f C:\ wamp64 \ www \ MyLogs \ my_script.php
有人可以指导可能出现的错误吗?我正在附上我的php脚本。
<?php
$conn = oci_connect('ABC', 'abcABC123', 'abcd1142/AXD');
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
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);
?>
答案 0 :(得分:0)
在尝试各种可能的方式来解决我的查询后,我发现这是两个php.ini文件。一种用于位于C:\ wamp \ bin \ php \ php5.4.16的命令行执行,而另一种则用于位于C:\ wamp \ bin \ apache \ Apache2.4.4 \ bin的Apache内部的PHP。您可以通过php -i(对于CLI)和(对于Web服务器)检查php.ini文件的位置。因此,当您想通过命令行运行脚本时,需要在php文件夹中的一个配置中进行更改。 只需取消注释或添加以下行: extension_dir =“ c:/wamp64/bin/php/php7.2.4/ext/” 扩展程序= php_oci8_12c.dll