· 8 years ago · May 21, 2018, 08:16 AM
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?>
33
34<?php
35 //CREATE CONNECTION
36 $servername = "localhost";
37 $username = "root";
38 $password = "root";
39 $conn = new mysqli($servername, $username, $password);
40 // CHECK THE CONNECTION
41 if ($conn->connect_error) {
42 die("Connection failed: " . $conn->connect_error);
43 }
44 // CREATE ESTATE AGENTS DATABASE
45 $sql = "CREATE DATABASE IF NOT EXISTS estate_agents";
46 if ($conn->query($sql) === TRUE) {
47 $dbname= "estate_agents";
48 $newConnection = new mysqli($servername, $username, $password,$dbname);
49 //CREATE PROPERTIES TABLE
50 $sql = "CREATE TABLE IF NOT EXISTS properties (
51 property_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
52 property_name VARCHAR(50) NOT NULL,
53 property_cost VARCHAR(50) NOT NULL,
54 property_description VARCHAR(500) NOT NULL
55 )";
56 if ( $newConnection->query($sql) === TRUE) {
57 $query = "SELECT * FROM properties";
58 $result = $newConnection->query($query);
59 foreach ($result as $row) {
60 $id = $row['property_id'];
61 $name = $row['property_name'];
62 $cost = $row['property_cost'];
63 $description = $row['property_description'];
64
65 echo $id;
66 }
67 }
68 else {
69 echo "Error creating table: " . $newConnection->error . "</br>";
70 }
71 }
72 else {
73 echo "estate_agents not functional: " . $newConnection->error . "</br>";
74 }
75?>
76
77<?php
78//CREATE CONNECTION
79$servername = "localhost";
80$username = "root";
81$password = "root";
82$conn = new mysqli($servername, $username, $password);
83// CHECK THE CONNECTION
84if ($conn->connect_error) {
85 die("Connection failed: " . $conn->connect_error);
86}
87$dbname= "estate_agents";
88$newConnection = new mysqli($servername, $username, $password,$dbname);
89//CREATE PROPERTIES TABLE
90$sql = "SELECT * FROM properties";
91$resultSet = $conn->query($sql);
92//to get the num rows, you have to mysqli_num_rows
93//you might want to create a function on your db class for num rows and return the count with return mysqli_num_rows($result);
94 $rowcount=$conn->numRows($resultSet);
95 // plz dont forget to create the function numRows on your class file