Hi, i created function that add a new table using array , i work with it on my projects ...
<?PHP
function array_keys_exist(&$key,array &$array){
$keys = split("\|",$key);
foreach($keys as $key_s){
if(array_key_exists($key_s, $array)) return true;
}
return false;
}
array_create_table(array &$array){
if(is_array($array)){
$key = "table|rows|values";
$info = "";
if(array_keys_exist($key,$array)){
if(is_array($array["rows"]) and is_array($array["values"]) ){
if(count($array["rows"]) == count($array["values"])) {
for($i=0; $i<=count($array["rows"]); $i++){
$info = $info." ".$array["rows"][$i]." ".$array["values"][$i]." NOT NULL ";
if($i < count($array["rows"])-1 ) $info = $info.",";
}
$query = "CREATE TABLE ".$this->private_tables_name.$array["table"]." ";
$query .= "( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ".$info." )";
return $query;
}
}
}else return "Error";
}
}
$database = new database(); $array = array("table"=>"MRO", "rows"=>array("name","username") , "values" => array("VARCHAR (50) "," VARCHAR (50) ") );
$query = array_create_table($array); if($database->query($query)) echo "Work"; else echo "Error"; ?>