Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > get mySQL column attributes in PHP?

get mySQL column attributes in PHP?
Thread Tools
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Feb 26, 2004, 05:53 PM
 
Hello,

Does anyone know if it is possible to get mySQL column attributes with PHP?

I am developing an addon for osCommerce and want it to work with both versions MS1 and MS2. There is just one area where a column has changed attributes that I'd like to run a check for (in one version it defaults to 1 and in the other it is auto-incrementing).
     
Registered User
Join Date: Jul 2003
Location: San Jose
Status: Offline
Reply With Quote
Feb 26, 2004, 11:02 PM
 
give this a whirl...

[php]
<?

$connect = mysql_connect("localhost", "user", "pass");
$db = mysql_select_db("database", $connect);

$query = "DESCRIBE table_name column_name";
$result = mysql_query($query, $connect);

list($field, $type, $null, $key, $default, $extra) = mysql_fetch_array($result);

if ($extra == NULL)
{
echo "column does not auto-increment";
}
else
{
echo "column auto-increments";
}

?>
[/php]
(Last edited by mzllr; Feb 27, 2004 at 02:11 AM. )
     
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Feb 27, 2004, 02:08 AM
 
perfect!

just what I was looking for.

Thank you very much!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2