implemented database, article cards, and parsing from markdown.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// Use environment variables for the database password and IP address.
|
||||
$db_user = $_ENV['DATABASE_USER'];
|
||||
$db_pass = $_ENV['DATABASE_PASSWORD'];
|
||||
$ip_addr = $_ENV['IP_ADDRESS'];
|
||||
|
||||
// Make some constants
|
||||
if ($_SERVER['HTTP_HOST'] == 'localhost') {
|
||||
define('HOST', 'localhost');
|
||||
define('USER', $db_user);
|
||||
define('PASS', $db_pass);
|
||||
define('DB', 'vintagecoding');
|
||||
} else {
|
||||
define('HOST', $ip_addr);
|
||||
define('USER', $db_user);
|
||||
define('PASS', $db_pass);
|
||||
define('DB', 'vintagecoding');
|
||||
}
|
||||
|
||||
/*
|
||||
* Handles any queries that should have only one row results.
|
||||
*/
|
||||
function query_db_one_result($query_stmt)
|
||||
{
|
||||
$conn = get_connection();
|
||||
$results = mysqli_query($conn, $query_stmt);
|
||||
mysqli_close($conn);
|
||||
|
||||
if (mysqli_num_rows($results) == 0 || mysqli_num_rows($results) > 1)
|
||||
return null;
|
||||
else
|
||||
return mysqli_fetch_assoc($results);
|
||||
}
|
||||
|
||||
function query_db_one_or_more_results($query_stmt)
|
||||
{
|
||||
$conn = get_connection();
|
||||
$results = mysqli_query($conn, $query_stmt);
|
||||
mysqli_close($conn);
|
||||
|
||||
if (mysqli_num_rows($results) == 0)
|
||||
return null;
|
||||
else
|
||||
return $results;
|
||||
}
|
||||
|
||||
function get_connection()
|
||||
{
|
||||
// Connect to the DB
|
||||
$conn = mysqli_connect(HOST, USER, PASS, DB);
|
||||
|
||||
return $conn;
|
||||
}
|
||||
Reference in New Issue
Block a user