Table-Creation Script : Table Create « MySQL Database « PHP






Table-Creation Script


<?
$db_name = "java2s";

$connection = @mysql_connect("mysql153.secureserver.net", "java2s", "password") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$columnNames = array("col1","col2","col3");
$columnTypes = array("int","Date","double");

$sql = "CREATE TABLE MyTable (";
for ($i = 0; $i < count($columnNames); $i++) {
     $sql .= $columnNames[$i]." ".$columnTypes[$i]. ", ";

}
$sql = substr($sql, 0, -2);
$sql .= ")";

echo($sql);

$result = mysql_query($sql,$connection) or die(mysql_error());

if ($result) {
     $msg = "<P>MyTable has been created!</P>";
     
     echo($msg);
}
?>

           
       








Related examples in the same category

1.Creating a Table in MySQL
2.Create new table in MySQL
3.Create table and install data