diff --git a/chapter11/project2/databaseConnect.inc.php b/chapter11/project2/databaseConnect.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..b3dda3ee7be358d15cde1ed2c3c7cda3a35e4d07 --- /dev/null +++ b/chapter11/project2/databaseConnect.inc.php @@ -0,0 +1,36 @@ + +<?php + # Generic php file mean to connect to an aribtrary database. + + function ConnectViaMySQLi($host, $user, $password){ + + # Create Connection. + $connection = mysqli_connect($host, $user, $password); + + # Check for valid Connection. + if ($connection->connect_error) { + die("Connection Failed: " . $connection->connect_error); + } + #echo "Connected Successfully!"; + } + + function ConnectViaPDO($host, $user, $password, $database, $DBport) { + + try { + # Create Connection. + $connectionString = "mysql:host=$host;port=$DBport;dbname=$database"; + $pdo = new PDO($connectionString, $user, $password); + + # Not sure what this does, but the w3schools example had it. + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + #echo "Connected Successfully!"; + + return $pdo; + } + catch(PDOException $e) { + echo "Connection Failed: " . $e->getMessage(); + } + } + +?> diff --git a/chapter11/project2/databaseLogin.inc.php b/chapter11/project2/databaseLogin.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..611c74707269db53f9fdf2f7500600b66f4a6f55 --- /dev/null +++ b/chapter11/project2/databaseLogin.inc.php @@ -0,0 +1,10 @@ +<?php + #$host = "localhost"; + $host = "127.0.0.1"; + $database = "bookcrm"; + $DBport = ""; + #$DBport = "3306"; + $DBuser = "root"; + $DBpassword = ""; +?> + diff --git a/chapter11/project2/sqlStatements.inc.php b/chapter11/project2/sqlStatements.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..262f33018d57a6946795160af7fae883851e8bd3 --- /dev/null +++ b/chapter11/project2/sqlStatements.inc.php @@ -0,0 +1,19 @@ + +<?php + # Generic SQL Statements. + + function SQLSelect($attributes, $tables) { + $query = "SELECT $attributes FROM $tables;"; + return $query; + } + + function SQLSelectOrder($attributes, $tables, $order) { + $query = "SELECT $attributes FROM $tables ORDER BY $order;"; + return $query; + } + + function SQLSelectOrderMatch($attributes, $tables, $order, $matcher, $matching) { + $query = "SELECT $attributes FROM $tables WHERE $matcher LIKE $matching ORDER BY $order;"; + return $query; + } +?> \ No newline at end of file