12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- // Connect to the MySQL database
- function db_connect() {
- $database = mysqli_connect("localhost", "mysqluser", "mysqlpassword", "ethicscanvas");
-
- if(!$database) {
- throw new Exception(mysqli_connect_errno() . ": " . mysqli_connect_error());
- }
-
- return $database;
-
- /*
- 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();
- }
-
- // Run query with a return
- function db_query_return($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 db_query_no_return($inDatabase, $inQuery) {
- if(!mysqli_query($inDatabase, $inQuery)) {
- throw new Exception(mysqli_errno($inDatabase) . ": " . mysqli_error($inDatabase));
- }
- }
- ?>
|