In next script or perhaps in your future, we may not deal with DBE (database Engine) we know or perhaps we will using complex DBE (Oracle for example). For this matter, you need to using PEAR or perhaps create a system that make you able to change the config but not all you script.
Let's begin with the solution for DBE not supported with auto number. First I created 1 table called as my_id contain only
- id
then I create a function that read the table add 1 then return the number. This function is same as function new id in PEAR. This is the function, you can edit to make sure is fit in your DBE.
I'm using mysql, then this script would be like this, if you using other.. can you share to me? just type in codepaste.net ... because sharing is good for you and me!
I'm using mysql, then this script would be like this, if you using other.. can you share to me? just type in codepaste.net ... because sharing is good for you and me!
<?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="UPDATE `my_id` SET `id` = '$id'"; $q=mysql_query($s); return $id; }
Tidak ada komentar:
Posting Komentar