public function create_table($table_name,$table_field,$field_type)
{
// dd($field_type);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db_fepb";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to create table
$sql = "CREATE TABLE $table_name (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,";
for($i=0;$i<count($table_field);$i++)
{
$sql=$sql.$table_field[$i].' '. $field_type[$i].', ';
}
$sql=$sql.'created_at TIMESTAMP';
$sql=$sql.')';
// dd($sql);
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
mysqli_close($conn);
}
Comments
Post a Comment