From 0badb07de2b57838c6501ecb0013b0bd04cec12e Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Wed, 26 Oct 2016 17:35:50 -0400
Subject: [PATCH] Add most of setup for connecting to database

---
 chapter11/project1/databaseConnect.inc.php | 30 ++++++++++++++++++++++
 chapter11/project1/databaseLogin.inc.php   |  7 +++++
 chapter11/project1/display-customers.php   | 12 +++++++++
 chapter11/project1/sqlStatements.inc.php   |  9 +++++++
 4 files changed, 58 insertions(+)
 create mode 100644 chapter11/project1/databaseConnect.inc.php
 create mode 100644 chapter11/project1/databaseLogin.inc.php
 create mode 100644 chapter11/project1/sqlStatements.inc.php

diff --git a/chapter11/project1/databaseConnect.inc.php b/chapter11/project1/databaseConnect.inc.php
new file mode 100644
index 0000000..4e8e40e
--- /dev/null
+++ b/chapter11/project1/databaseConnect.inc.php
@@ -0,0 +1,30 @@
+
+<?php
+	# Generic php file mean to connect to an aribtrary database.
+
+	function ConnectViaMySQLi($host, $user, $password, $database){
+		$connection = mysqli_connect($host, $user, $password, $database);
+
+		$error = mysql_error();
+		if ($error != null) {
+			$output = "<p>Unable to connect to database.</p>" . $error;
+			exit($output);
+		}
+	}
+
+	function ConnectViaPDO($host, $user, $password, $database) {
+
+		try {
+			$connectionString = "mysql:host=$host:dbname=$database";
+			#echo '$connectionString = ';
+			#echo $connectionString;
+			$pdo = new PDO($connectionString, $user, $password);
+
+			echo "Connected Successfully!";
+		}
+		catch(PDOException $e) {
+			die($e->getMessage());
+		}
+	}
+
+?>
diff --git a/chapter11/project1/databaseLogin.inc.php b/chapter11/project1/databaseLogin.inc.php
new file mode 100644
index 0000000..32c54ae
--- /dev/null
+++ b/chapter11/project1/databaseLogin.inc.php
@@ -0,0 +1,7 @@
+<?php
+	$host = "localhost";
+	$database = "bookcrm";
+	$DBuser = "root";
+	$DBpassword = "";
+?>
+
diff --git a/chapter11/project1/display-customers.php b/chapter11/project1/display-customers.php
index 442c074..32f4129 100644
--- a/chapter11/project1/display-customers.php
+++ b/chapter11/project1/display-customers.php
@@ -1,6 +1,18 @@
 <?php
+  
+  # Initialize database connection variables specific to this page.
+  include "databaseLogin.inc.php";
 
+  include "databaseConnect.inc.php";
 
+  #ConnectViaMySQLi($host, $DBuser, $DBpassword, $database);
+  #ConnectViaPDO($host, $DBuser, $DBpassword, $database);
+
+  #include "sqlStatements.inc.php";
+  #Initially load databases.
+  #$sqlCustomers = SQLSELECT("*", "Customers");
+  #$sqlCategories = SQLSELECT("*", "Categories");
+  #$sqlImprints = SQLSELECT("*", "Imprints");
 
 ?>
 
diff --git a/chapter11/project1/sqlStatements.inc.php b/chapter11/project1/sqlStatements.inc.php
new file mode 100644
index 0000000..047da42
--- /dev/null
+++ b/chapter11/project1/sqlStatements.inc.php
@@ -0,0 +1,9 @@
+
+<?php
+	# Generic SQL Statements.
+
+	function SQLSelect($attributes, $tables) {
+		$query = "SELECT $attributes FROM $tables;";
+		return $query;
+	}
+?>
\ No newline at end of file
-- 
GitLab