Re: MDB & multiple column indexes
| From: | Lukas Smith | Date: | Fri, 01 Jul 2005 23:18:16 +0000 |
| Subject: | Re: MDB & multiple column indexes | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19851@lists.php.net to get a copy of this message | ||
Justin Koivisto wrote:
In the midst of creating a dynamic table, I need to be able to create a
unique index using two fields. To better illustrate what I need to do,
this is how I do it from the mysql command line:
ALTER TABLE table_name ADD PRIMARY KEY (field_one, field_two);
I realize that MDB doesn't support primary keys, so the next approach
would be:
ALTER TABLE table_name ADD UNIQUE key_name (field_one, field_two);
The best I have gotten is like this:
$idx=array(
'FIELDS'=>array(
'field_one'=>array(),
'field_two'=>array()
)
);
$result=$mdb->createIndex($table_name,$key_name,$idx);
Which results in the same as:
ALTER TABLE table_name ADD INDEX key_name (field_one, field_two) ;
all you need is a "unique" key with some value next to the "FIELDS" key inside your array and you should get a unique index.
regards,
Lukas