I am new to PHP but very familiar with databases. I have written a simple piece of code to log requests in a MySQL table when the index.php file is processed.
Code: Select all
<?php
require '../header.php' ;
$dbc = mysql_connect ($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db) or die('Cannot select database!') ;
$rem_addr = $_SERVER["REMOTE_ADDR"] ;
$ins = "INSERT INTO requests(conn_addr, hits, timestamp) VALUES ('$rem_addr' , 1, NOW())" ;
$upd = "UPDATE requests SET hits = hits + 1, timestamp = NOW() WHERE conn_addr = '$rem_addr'" ;
$result = mysql_query($ins) ;
if (!$result)
$result = mysql_query($upd) ;
?>
(the database connection is closed later).Is this a known problem with Apache / PHP?
Note that if I debug this with Gubed this does not happen.