使用PHP将Apache日志文件插入到Oracle数据库

时间:2018-07-24 07:51:38

标签: php oracle apache

将Apache日志文件上传到oracle数据库时,NULL值正在上传。第一次运行时,此代码运行良好,但后来又上传了NULL值。

<?php
$conn = oci_connect('USR1', 'Root1zed', 'ufhdhdh/DBAY');
if (!$conn) {
   $m = oci_error();
   echo $m['message'], "\n";
   exit;
}
else {
   print "Connected to Oracle!";
   }
$myfile = fopen("access.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
	$content= fgets($myfile);
	$carray=explode(' ',$content);
	

	$stdii = 'INSERT INTO LOGS(IP_ADDRESS, USER_IDENTIFIER, USERID , REQUEST_TIME , CLIENT_REQUEST ,RESPONSE_CODE ,SIZEOFOBJECT, COOKIES)'.
	'values(:IP_ADDRESS, :USER_IDENTIFIER, :USERID , :REQUEST_TIME , :CLIENT_REQUEST ,:RESPONSE_CODE ,:SIZEOFOBJECT, :COOKIES)';
	$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_execute($compiled1, OCI_COMMIT_ON_SUCCESS);
}
oci_close($conn);
fclose($myfile);
?>

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。

代码为:

$carray=explode(',',$content);
**list($IP_ADDRESS, $USER_IDENTIFIER, $USERID , $REQUEST_TIME , $CLIENT_REQUEST ,$RESPONSE_CODE ,$SIZEOFOBJECT, $COOKIES)=$carray;**