2019-01-26 22:34:48 +00:00
|
|
|
<?php
|
|
|
|
require_once ( 'config.php' );
|
|
|
|
function db_connect ( ) {
|
|
|
|
global $config;
|
|
|
|
$connection = new MySQLi ( $config [ 'db' ] [ 'host' ], $config [ 'db' ] [ 'username' ], $config [ 'db' ] [ 'password' ], $config [ 'db' ] [ 'name' ], $config [ 'db' ] [ 'port' ] );
|
|
|
|
if ( $connection->connect_errno ) {
|
|
|
|
die ( "Database connection failed." );
|
|
|
|
}
|
|
|
|
return $connection;
|
|
|
|
}
|
|
|
|
function db_prepare ( MySQLi $connection, string $query ) {
|
|
|
|
if ( ! ( $statement = $connection -> prepare ( $query ) ) ) {
|
|
|
|
die ( "Prepare failed: (" . $connection->errno . ") " . $connection->error );
|
|
|
|
}
|
|
|
|
return $statement;
|
|
|
|
}
|
|
|
|
function db_bind ( MySQLi_stmt $statement, array $params ) {
|
|
|
|
if ( ! call_user_func_array ( array ( $statement, "bind_param" ), array_merge ( $params [ 0 ], $params [ 1 ] ) ) ) {
|
|
|
|
die ( "Binding parameters failed: (" . $statement->errno . ") " . $statement->error );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function db_execute ( $statement ) {
|
|
|
|
if ( ! $statement->execute ( ) ) {
|
|
|
|
die ( "Execute failed: (" . $statement->errno . ") " . $statement->error );
|
|
|
|
}
|
|
|
|
}
|
2019-02-07 11:36:44 +00:00
|
|
|
function split_uri_array ( string $php_self, string $request_uri ) : Array {
|
|
|
|
$uri = substr ( $request_uri, strlen ( substr ( $php_self, 0, strrpos ( $php_self, 'index.php' ) ) ), strlen ( $request_uri ) - strlen ( substr ( $php_self, 0, strrpos ( $php_self, 'index.php' ) ) ) );
|
|
|
|
$arr = Array ( );
|
|
|
|
$last_arg_pos = 0;
|
|
|
|
for ( $i = 1; $i < ( strlen ( $uri ) ) - 1; $i ++ ) {
|
|
|
|
if ( substr ( $uri, $i, 1 ) == "/" && substr ( $uri, $i + 1, 1 ) != "/" && substr ( $uri, $i - 1, 1 ) != "/" ) {
|
|
|
|
$arr [ ] = substr ( $uri, $last_arg_pos, $i - $last_arg_pos);
|
|
|
|
$last_arg_pos = $i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$arr [ ] = substr ( $uri, $last_arg_pos, $i - $last_arg_pos + 1);
|
|
|
|
return $arr;
|
|
|
|
}
|
2019-01-26 22:34:48 +00:00
|
|
|
?>
|