Add database module draft
This commit is contained in:
parent
ded3e330e8
commit
ae59e1376b
|
@ -3,9 +3,11 @@
|
|||
with pkgs;
|
||||
|
||||
mkShell {
|
||||
buildInputs = [ php mysql57 ];
|
||||
buildInputs =
|
||||
[ php74 php74Extensions.pdo_mysql php74Packages.composer mysql57 ];
|
||||
|
||||
shellHook = ''
|
||||
pkill mysql
|
||||
rm -rf .mysql && mkdir .mysql
|
||||
|
||||
mysqld --datadir="$(pwd)/.mysql" --socket="$(pwd)/.mysql/mysql.sock" --initialize-insecure
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue