1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- /*
- // Connect to the MySQL database
- function db_connect() {
-
- include('config.php');
- if(isset($db_host, $db_username, $db_password, $db_name)) {
- // Create connection to database
- $conn = new mysqli($db_host, $db_username, $db_password, $db_name);
- if ($conn->connect_error) {
- echo 4004; // Unsuccessful connection to database
- }
- }
- else { // Connection variables not set
- echo 4005; // Respond with bad-request code
- }
-
- return $conn;
- }
- */
-
- /*
- // Closes the connection to the database
- function db_close($conn) {
- $conn->close();
- }
- */
-
- // Connect to the database
- function databaseConnect() {
- $database = mysqli_connect("localhost", "mysqluser", "mysqlpassword", "ethicscanvas");
-
- if(!$database) {
- throw new Exception(mysqli_connect_errno() . ": " . mysqli_connect_error());
- }
-
- return $database;
- }
-
- // Run query with a return
- function databaseQueryWithReturn($inDatabase, $inQuery) {
- if(!$recordSet = mysqli_query($inDatabase, $inQuery)) {
- throw new Exception(mysqli_errno($inDatabase) . ": " . mysqli_error($inDatabase));
- }
-
- return $recordSet;
- }
-
- // Run query without any return
- function databaseQueryNoReturn($inDatabase, $inQuery) {
- if(!mysqli_query($inDatabase, $inQuery)) {
- throw new Exception(mysqli_errno($inDatabase) . ": " . mysqli_error($inDatabase));
- }
- }
-
- // Close the connection to the database
- function databaseClose($inDatabase) {
- if(!mysqli_close($inDatabase)) {
- throw new Exception(mysqli_connect_errno() . ": " . mysqli_connect_error());
- }
- }
- ?>
|