Table creation

This commit is contained in:
Daniel Løvbrøtte Olsen 2016-05-15 01:35:08 +02:00
parent 98fff1b107
commit 0650a6df99

View File

@ -4,11 +4,16 @@ $config = parse_ini_file('config.ini');
$conn = mysqli_connect($config['db_host'], $config['db_user'], $config['db_password'], 'blomzt');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
if (mysqli_connect_errno()) {
die("Connection failed: " . mysqli_connect_error());
}
if (!TableExists($config['db_table'], $conn)) {
$sql = 'CREATE TABLE ' . $config['db_table'] . ' (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, location Point NOT NULL, url VARCHAR(65), date_added TIMESTAMP)
';
mysqli_query($conn, $sql);
}
?>
@ -19,6 +24,17 @@ if ($conn->connect_error) {
<title>Blomzt</title>
</head>
<body>
</body>
</html>
</html>
<?php
// Functions
function TableExists($table, $conn) {
$res = mysqli_query($conn, 'SHOW TABLES LIKE \'$table\'');
return mysqli_num_rows($res) > 0;
}
?>