Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //CREATE CONNECTION
- $servername = "localhost";
- $username = "root";
- $password = "root";
- $conn = new mysqli($servername, $username, $password);
- // CHECK THE CONNECTION
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // CREATE ESTATE AGENTS DATABASE
- $sql = "CREATE DATABASE IF NOT EXISTS estate_agents";
- if ($conn->query($sql) === TRUE) {
- $dbname= "estate_agents";
- $newConnection = new mysqli($servername, $username, $password,$dbname);
- //CREATE PROPERTIES TABLE
- $sql = "CREATE TABLE IF NOT EXISTS properties (
- property_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
- property_name VARCHAR(50) NOT NULL,
- property_cost VARCHAR(50) NOT NULL,
- property_description VARCHAR(500) NOT NULL
- )";
- if ( $newConnection->query($sql) === TRUE) {
- }
- else {
- echo "Error creating table: " . $newConnection->error . "</br>";
- }
- }
- else {
- echo "estate_agents not functional: " . $newConnection->error . "</br>";
- }
- ?>
- <?php
- //CREATE CONNECTION
- $servername = "localhost";
- $username = "root";
- $password = "root";
- $conn = new mysqli($servername, $username, $password);
- // CHECK THE CONNECTION
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // CREATE ESTATE AGENTS DATABASE
- $sql = "CREATE DATABASE IF NOT EXISTS estate_agents";
- if ($conn->query($sql) === TRUE) {
- $dbname= "estate_agents";
- $newConnection = new mysqli($servername, $username, $password,$dbname);
- //CREATE PROPERTIES TABLE
- $sql = "CREATE TABLE IF NOT EXISTS properties (
- property_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
- property_name VARCHAR(50) NOT NULL,
- property_cost VARCHAR(50) NOT NULL,
- property_description VARCHAR(500) NOT NULL
- )";
- if ( $newConnection->query($sql) === TRUE) {
- $query = "SELECT * FROM properties";
- $result = $newConnection->query($query);
- foreach ($result as $row) {
- $id = $row['property_id'];
- $name = $row['property_name'];
- $cost = $row['property_cost'];
- $description = $row['property_description'];
- echo $id;
- }
- }
- else {
- echo "Error creating table: " . $newConnection->error . "</br>";
- }
- }
- else {
- echo "estate_agents not functional: " . $newConnection->error . "</br>";
- }
- ?>
- <?php
- //CREATE CONNECTION
- $servername = "localhost";
- $username = "root";
- $password = "root";
- $conn = new mysqli($servername, $username, $password);
- // CHECK THE CONNECTION
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $dbname= "estate_agents";
- $newConnection = new mysqli($servername, $username, $password,$dbname);
- //CREATE PROPERTIES TABLE
- $sql = "SELECT * FROM properties";
- $resultSet = $conn->query($sql);
- //to get the num rows, you have to mysqli_num_rows
- //you might want to create a function on your db class for num rows and return the count with return mysqli_num_rows($result);
- $rowcount=$conn->numRows($resultSet);
- // plz dont forget to create the function numRows on your class file
Add Comment
Please, Sign In to add comment