03-05-2008, 03:07 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
Here is a snippet that would use your purpose, but in different format..
So your table data would look like this
Code:
table:users|user:VARCHAR;255;NOT NULL,passwd:VARCHAR;128;NOT NULL
:/
PHP Code:
<?php
$t = "table:users|user:VARCHAR;255;NOT NULL,passwd:VARCHAR;128;NOT NULL";
$d = explode( '|', $t );
$_table = explode( ':', $d['0']);
$tableName = $_table['1'];
$sql = "CREATE TABLE ".$tableName." ( \n";
$rows = explode( ',', $d['1']);
$c = count( $rows)-1;
$count = 0;
foreach( $rows as $_n => $row ) {
$sql .= "\t";
$_ro = explode( ':', $row);
$fieldName = $_ro['0'];
$fieldOpt = $_ro['1'];
$fields = explode( ';', $fieldOpt);
$sql .= "".$fieldName." ".$fields['0']." (".$fields['1']." ) ".$fields['2'];
if ( $count < $c ) {
$sql .= ",";
}
$sql .= "\n";
$count++;
}
$sql .= ")ENGINE = MYISAM;";
echo $sql;
?>
Outputs:
Code:
CREATE TABLE users (
user VARCHAR (255 ) NOT NULL,
passwd VARCHAR (128 ) NOT NULL
)ENGINE = MYISAM;
__________________
Back from sysadmins to the programmers.
|
|
|