-2

I have a db_connect.php which holds all information for the database. I now want to check if database exists and if not, create it.

Then i want to check if the used table exists, and if not, create it. Anyone have an idea how I exactly do this?

Here is my db_connect.php:

<?php
//outsourced db-informations
$db_host = 'localhost';
$db_user = 'root';
$db_passwort = '';
$db_name = 'test_db';
$db_table = 'data';
$db_mysqli = mysqli_connect("$db_host","$db_user","$db_passwort", "$db_name");
mysqli_connect("$db_host","$db_user","$db_passwort", "$db_name") or die
("Keine Verbindung moeglich");
?>
whatever.idc
  • 92
  • 1
  • 1
  • 10
  • 1
    Possible duplicate of [Check if a database table exists using PHP/PDO](https://stackoverflow.com/questions/1717495/check-if-a-database-table-exists-using-php-pdo) – LF00 Jun 08 '17 at 08:28
  • Possible duplicatee of MySQL - https://stackoverflow.com/questions/44430422/php-check-if-database-and-table-exists-if-not-create-it – Fahad Anjum Jun 08 '17 at 08:29
  • Possible duplicate of [create mysql table if it doesn't exist](https://stackoverflow.com/questions/25145574/create-mysql-table-if-it-doesnt-exist) – Masivuye Cokile Jun 08 '17 at 09:26

1 Answers1

1

The query will look like

CREATE TABLE IF NOT EXISTS tbl_user (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
uname    CHAR(10) NOT NULL,
regdate  DATE NOT NULL)
PHP_RIDER
  • 355
  • 1
  • 12