View Single Post
Old 03-05-2008, 03:07 PM   #3 (permalink)
abiko
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

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.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote