Add database module draft

This commit is contained in:
coolneng 2020-05-18 15:42:14 +02:00
parent ded3e330e8
commit ae59e1376b
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 16 additions and 1 deletions

View File

@ -3,9 +3,11 @@
with pkgs; with pkgs;
mkShell { mkShell {
buildInputs = [ php mysql57 ]; buildInputs =
[ php74 php74Extensions.pdo_mysql php74Packages.composer mysql57 ];
shellHook = '' shellHook = ''
pkill mysql
rm -rf .mysql && mkdir .mysql rm -rf .mysql && mkdir .mysql
mysqld --datadir="$(pwd)/.mysql" --socket="$(pwd)/.mysql/mysql.sock" --initialize-insecure mysqld --datadir="$(pwd)/.mysql" --socket="$(pwd)/.mysql/mysql.sock" --initialize-insecure

13
src/database.php Normal file
View File

@ -0,0 +1,13 @@
<?php
function connectDatabase($user, $pass, $db) {
$unix_socket = '.mysql/mysql.sock';
$charset = 'utf8mb4';
$dsn = "mysql:unix_socket=$unix_socket;dbname=$db;charset=$charset";
$db_connection = new PDO($dsn, $user, $pass);
return $db_connection;
}
function closeDatabase($db_connection) {
$db_connection = null;
}