How to tell if a field type is auto_increment
How to tell if a field type is auto_increment
am 29.01.2007 23:06:12 von John
I've been struggling to figure a way to determine if a mySql filed type is
auto inc.
Any ideas?
Iv'e written a function that will INSERT form data which has the exact field
names as the mysql table, thus looping through the table names and then
building a query string for the insert. However I'd like to skip a field
that's autoinc. That can be done if there's no hidden field in the form with
the same name. I've created another function that updates a table but only
with values in the http form that have changed, using the same logic as
above, except I have to have a hidden field of the autoinc field so I know
whcih row to update. Obviously the autoinc field won't be changed.
Thanks a million in advance.
--
Regards,
John L. Creed
pcExpressWay Consulting
*****************************************
dBASE Gold Charter Member 210
*****************************************
http://www.pcexpressway.com
*****************************************
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to tell if a field type is auto_increment
am 29.01.2007 23:52:09 von Niel Archer
Hi
Try using:
SHOW COLUMNS FROM db.table LIKE 'field_name%'
and from the returned row, check the 'Extra' column for 'auto_increment'
Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to tell if a field type is auto_increment
am 30.01.2007 00:20:02 von John
Thanks a Million my Friend. I've been struggling with this for days now
--
Regards,
John L. Creed
pcExpressWay Consulting
*****************************************
dBASE Gold Charter Member 210
*****************************************
http://www.pcexpressway.com
*****************************************
"Niel Archer" wrote in message
news:20070129224943.FD72.NIEL@catweasel.org...
> Hi
>
> Try using:
> SHOW COLUMNS FROM db.table LIKE 'field_name%'
>
> and from the returned row, check the 'Extra' column for 'auto_increment'
>
> Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to tell if a field type is auto_increment
am 30.01.2007 20:30:53 von John
Here's what I did wih your help:
function isAutoinc($table,$fieldname){
// returns 0 if false, 1 if true
$breturn = 0;
$sql = "SHOW COLUMNS FROM $table LIKE '$fieldname%' ";
$result = mysql_query($sql) or die("Couldn't open table");
// check column Extra
$row = mysql_fetch_array( $result );
if( $row["Extra"] == "auto_increment" ){
$breturn = 1;
}
mysql_free_result($result);
return $breturn;
}
Thanks again!!!
--
Regards,
John L. Creed
pcExpressWay Consulting
*****************************************
dBASE Gold Charter Member 210
*****************************************
http://www.pcexpressway.com
*****************************************
"Niel Archer" wrote in message
news:20070129224943.FD72.NIEL@catweasel.org...
> Hi
>
> Try using:
> SHOW COLUMNS FROM db.table LIKE 'field_name%'
>
> and from the returned row, check the 'Extra' column for 'auto_increment'
>
> Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to tell if a field type is auto_increment
am 30.01.2007 20:52:57 von Niel Archer
Hi John,
I'd suggest searching within the Extra field instead of testing for the
value explicitly, as this field can theoretically hold several extra
pieces of information.
Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to tell if a field type is auto_increment
am 03.02.2007 16:04:37 von John
Ahhh, thanks. I'll do that.
--
Regards,
John L. Creed
pcExpressWay Consulting
*****************************************
dBASE Gold Charter Member 210
*****************************************
http://www.pcexpressway.com
*****************************************
"Niel Archer" wrote in message
news:20070130195118.B5A4.NIEL@catweasel.org...
> Hi John,
>
> I'd suggest searching within the Extra field instead of testing for the
> value explicitly, as this field can theoretically hold several extra
> pieces of information.
>
> Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php