I wrote a script to log MySQL connections into a log file ...
So that whenever and wherever in the different part of the scripts , I need to connect , I could use this code to connect as well as track the connections to a log.
This is the code.
[PHP]
<?
$username="xxxx";
$password="xxxx";
$port="xx";
$ip = getenv("REMOTE_ADDR") ; // User IP address
$host="xxxx";
$database="xxxx";
$logfile="./conlog.txt";
$time=date("d/m/Y - H:i:s A");
$connectid=mysql_connect($host,$username,$password );
if($connectid){$log1="Connecting to server [$host]....Done";}
else{$log1="Connecting to server [$host]....Failed (".mysql_error().")";}
$connectdbid=mysql_select_db($database);
if($connectdbid){$log2="Switching to database [$database]....Done";}
else{$log1="Switching to database [$database]....Failed (".mysql_error().")";}
// Log Processes (./log.)
$usr="\nRequest from user [$ip] on [$time]";
$log=$usr."\n$log1\n$log2";
$fp=fopen($logfile,"a");
$add1=fputs($fp,$log);
$close1=fclose($fp);
//done
?>
[/PHP]
This thing is working but whenever I include it with the PHP's
function in other parts of the script , I get this error:
-
Warning: fopen(./conlog.txt) [function.fopen]: failed to open stream: Permission denied in /home/veg1/public_html/modules/connectdb/connectsqldb.php on line 27
-
-
Warning: fputs(): supplied argument is not a valid stream resource in /home/veg1/public_html/modules/connectdb/connectsqldb.php on line 28
-
-
Warning: fclose(): supplied argument is not a valid stream resource in /home/veg1/public_html/modules/connectdb/connectsqldb.php on line 29
-
Please help me asap.
Thanks so much.