2012-07-01

My Id plus log

I just could helped when see table id only using that's way.. taken the value then add 1!! I suddenly realise this can be use as log and I can integrated with other table!! in fact the auto id from my table using this and is really help me to found error and log related to the table.

For the start, I'm using mysql, you can change into your DBE(Database Engine) U use right now! the table contain:

  • id. Primary key (Integer)
  • ip. index (char)this is for log purpose
  • time. unique(datetime or timestamp) is better autoupdate then input it
for the ip, we using variable $_SERVER['REMOTE_ADDR']
<?php function newId() { /* view the last value */ $s='select id from my_id order by desc limit 1'; $q=mysql_query($s); $r=mysql_fetch_array($q); $id=$r[0]+1; /* view the last value */ $s="insert into `my_id` values($id,'$_SERVER['REMOTE_ADDR']',now())"; $q=mysql_query($s); return $id; }
for time, I rather using timestamp because it have auto update time. So you don't need to type now() actualy.   The number I have then using with other table like user, then if you want to know when the user created, just peek on this. You will have IP created the user and what time the user created. This log can be used and integrated with log!!

Tidak ada komentar: