Solved

in MSSQL, how can i retrieve accepted values as list equivalent to MySQL ENUM values? PHP preferred

Posted on 2009-05-13
2
582 Views
Last Modified: 2013-12-12
I wish to (in PHP) dynamically retrieve a list of acceptable/available values for a column in a MSSQL database, for a field which has a Check Constraint to try to get functionality similar to MySQL ENUM data type.

Is there an easier way to do this?  with MySQL it's apparently quite simple (see code).  MSSQL has a string for the Check Constraints and takes a lot of effort to get to in the schema.

from the site http://dev.mysql.com/doc/refman/5.0/en/enum.html :
This is an extremely simple way to get the options from an enum into an array, here called $arryEnum
 
<?php
$result=mysql_query("SHOW COLUMNS FROM <table> LIKE '<column>'");
if( mysql_num_rows( $result ) > 0 )
{
   $row=mysql_fetch_row($result);
   preg_match_all("/'(.*?)'/", $row['Type'], $matches);
   $arryEnum= $matches[1];
}
?> 
 
The important bit is the regexp, which just matches anything in apostrophes.

Open in new window

0
Comment
Question by:labops
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
racek earned 500 total points
ID: 24377789
0
 
LVL 2

Author Comment

by:labops
ID: 24379202
Nice.   That gets a little closer, I see the check constraint but not the parameters I'd set.  I was able to find the information from joining two information_schema tables.
Is there a better way to go about this from the start?  It sure would be nice to have that ENUM :(
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question