Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Author: Porn (KimChoJapFan)
- * Date: March 26, 2017
- * Version: a01
- */
- //ABOUT: Prevent direct access to this file.
- if(!defined('LOCK')) { die('ACCESS DENIED!'); }
- //ABOUT: Import necessary files.
- require $_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php';
- //ABOUT: Create the Database class.
- class Database {
- //ABOUT: Connect to the database using PDO.
- function connect() {
- //ABOUT: Set local variable values from the config.inc.php file.
- $hostname = HOSTNAME;
- $database = DATABASE;
- $username = USERNAME;
- $password = PASSWORD;
- $charset = CHARSET;
- $sqlport = SQLPORT;
- //ABOUT: Create PDO connection to the database.
- $dsn = "mysql:host=$hostname;dbname=$database;port=$sqlport;charset=$charset";
- $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => FALSE];
- return new PDO($dsn, $username, $password, $opt);
- }
- //ABOUT: Send data to the database.
- function send($pdo,$query,$data) {
- //ABOUT: Prepare statements to secure against SQL injections.
- $stmt = $pdo->prepare($query);
- $stmt->execute($data);
- }
- //ABOUT: Receive data from the database.
- function gather($pdo, $query) {
- //ABOUT: Prepare statements to secure against SQL injections.
- $stmt = $pdo->prepare($query);
- $stmt->execute();
- return $stmt->fetchAll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement