diff --git a/chapter11/project1/databaseConnect.inc.php b/chapter11/project1/databaseConnect.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..4e8e40e546fb05437c01a35379c64d56b191e3dc --- /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 0000000000000000000000000000000000000000..32c54ae592e3b9896efa65c188b165152fe05b0e --- /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 442c0741955965bb50dd01fc156dd6fbbdea01fb..32f412942c722fd7a98408d03af28ca4477077c0 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 0000000000000000000000000000000000000000..047da428bba5e80df8d84227f7420605b7fd84a7 --- /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