· 10 years ago · Apr 13, 2016, 03:24 PM
1<?php
2 //CREATE CONNECTION
3 $servername = "localhost";
4 $username = "root";
5 $password = "root";
6 $conn = new mysqli($servername, $username, $password);
7 // CHECK THE CONNECTION
8 if ($conn->connect_error) {
9 die("Connection failed: " . $conn->connect_error);
10 }
11 // CREATE ESTATE AGENTS DATABASE
12 $sql = "CREATE DATABASE IF NOT EXISTS estate_agents";
13 if ($conn->query($sql) === TRUE) {
14 $dbname= "estate_agents";
15 $newConnection = new mysqli($servername, $username, $password,$dbname);
16 //CREATE PROPERTIES TABLE
17 $sql = "CREATE TABLE IF NOT EXISTS properties (
18 property_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
19 property_name VARCHAR(50) NOT NULL,
20 property_cost VARCHAR(50) NOT NULL,
21 property_description VARCHAR(500) NOT NULL
22 )";
23 if ( $newConnection->query($sql) === TRUE) {
24 }
25 else {
26 echo "Error creating table: " . $newConnection->error . "</br>";
27 }
28 }
29 else {
30 echo "estate_agents not functional: " . $newConnection->error . "</br>";
31 }
32?>