Mailing List Archive



Back to the month index Back to the list index

Michel BLANC (leucos@avignon.pacwan.net)
Wed, 23 Apr 1997 16:38:48 +0200 (MET DST)


Date: Wed, 23 Apr 1997 16:38:48 +0200 (MET DST)
From: Michel BLANC <leucos@avignon.pacwan.net>
Subject: Re: [mSQL] Automatic field identifier?
Message-Id: <Pine.LNX.3.95.970423162920.14504A-100000@www.opali.fr>

On Tue, 22 Apr 1997, Oscar Santos wrote:

> Hello friends!
>
> I'm new in mSQL and of course i've a question for you:
>
> When I insert a record in my database, Is there a way that
> msql automatically gives him a unique identifier?
>
> example
>
> Table : people
>
> create table people( IDpeople int, name char(50))
>
> .( I don4t know?).
>
> insert into people values ( $what, 'Oscar Santos')
>
> Note I use a database whith some tables with relationships between them.

You can try this and use the _seq internal variable. If I do not make
mistakes, you can go like this :

Note : don't copy the comments
===========================================================
$sock = msqlConnect();
if ($sock < 0)
        {
        fatal("Error : $ERRMSG\n");
        }
        
if (msqlSelectDB($sock,"address") < 0)
        {
        fatal("Error : $ERRMSG\n");
        }

//retrieving _seq value from the people table (differs from one table to
the other

if (msqlQuery($sock,"select _seq from people") < 0)
        {
        fatal("Error : $ERRMSG\n");
        }

//now the query returned one row containing one field containing the seq
value

$res = msqlStoreResult();
$row = msqlFetchRow($res);

//here, insertion of Oscar with id=_seq
$query = "insert into people values ( " + $row[0] + ",'OscarSantos')"

if (msqlQuery($sock,$query) < 0)
        {
        fatal("Error : $ERRMSG\n");
        }

echo("<H2>Good for you :)</H2>\n");
=====================================================================

--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!