griimnak
You're a slave to the money then you die
As you may know, mysql is depreciated in the latest php release.
You could use mysqli but i prefer pdo. this is a database class that I use on my personal site:
database.php:
config.php:
finally, the usage
index.php:
it's simple and gets the job done. Keep in mind php isn't my best language, but this is good base for you to build upon.
You could use mysqli but i prefer pdo. this is a database class that I use on my personal site:
database.php:
PHP:
class Database {
public static function dbConnect() {
global $config;
try {
$username = $config['db']['user'];
$password = $config['db']['pass'];
$dbb = $config['db']['database'];
$hostname = $config['db']['host'];
$conn = new pdo("mysql:host=$hostname;dbname=$dbb;", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
} catch(PDOException $e) {
$dberror = '<b style="text-color: red;"> Output a custom error with style </b>';
die($dberror);
}
}
}
config.php:
PHP:
$config['db']['host'] = 'localhost';
$config['db']['user'] = 'root';
$config['db']['pass'] = 'pass';
$config['db']['database'] = 'db';
finally, the usage
index.php:
PHP:
require_once 'config.php';
require_once 'database.php';
$query = Database::dbConnect()->prepare("SELECT * FROM sometable");
$query->execute();
$result = $query->fetchAll();
foreach($result as $row) {
$certain_row = $row['username'];
}
if($certain_row == 'griimnak'){
echo 'hi griimnak';
}
it's simple and gets the job done. Keep in mind php isn't my best language, but this is good base for you to build upon.