1. Go to this page and download the library: Download alexsasharegan/database library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Database\MySQL;
# Takes a MySQL-formatted date string and returns a string file path
MySQL::SQLDateToPath( string $SQLDate );
# example
echo MySQL::SQLDateToPath( '2016-09-06 14:02:26' );
# Outputs: '2016/09/06'
# Returns a MySQL-formatted timestamp
echo MySQL::now();
# Outputs: '2016-09-06 14:04:15';
$mySQL = new \Database\MySQL($connectionOptions, $pdoOptions);
# use a try/catch block to handle a bad query
try {
$mySQL->select(['firstName', 'lastName'])
->from('users')
->where('id', 'in', [1,2,3])
# we can chain methods together here
->map(
# this can be any callable type ( will be called with each row )
# closures let us 'use' vars from parent scope
# be wary of when you need to pass by reference using &
function ( array $resultRow )
{
$users[] = new User($resultRow); # the $resultRow is an associative array
}
);
} catch ( Exception $e ) {
# insert some custom error handling here
exit( $e );
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.