PHP code example of aleksey.nemiro / nemiro.data.php
1. Go to this page and download the library: Download aleksey.nemiro/nemiro.data.php 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/ */
// client for MySql
use Nemiro\Data\MySql as MySql;
// client for PostgreSQL
use Nemiro\Data\PgSql as PgSql;
// query builder
use Nemiro\Data\DBCommand as DBCommand;
// create client instance for MySql
$client = new MySql();
// create a new command
$client->Command = new DBCommand('SELECT * FROM messages');
// get table
$table = $client->GetTable();
// output the table rows
echo '<pre>';
foreach($table as $row)
{
print_r($row);
}
echo '</pre>';
// create client instance for MySql
$client = new MySql();
// create a new command
$client->Command = new DBCommand
(
'INSERT INTO users (username, date_created) '.
'VALUES (@username, @date_created)'
);
// @username and @date_created is parameters name,
// add a values for this parameters
$client->Command->Parameters->Add('@date_created')->SetValue(date('Y-m-d H-i-s'));
$client->Command->Parameters->Add('@username')->SetValue('anyname');
// execute the command
$newId = $client->ExecuteScalar();
echo 'ID = '.$newId;
// create client instance for MySql
$client = new MySql();
// create commands
$firtCommand = new DBCommand('SELECT * FROM users WHERE is_blocked = 0');
$secondCommand = new DBCommand
(
'SELECT * FROM messages WHERE id_users IN '.
'(SELECT id_users FROM users WHERE is_blocked = 0) AND '.
'subject LIKE @search_subject'
);
$secondCommand->Parameters->Add('@search_subject', '%hello%');
$thirdCommand = 'SELECT * FROM files';
// etc...
// add commands to client
$client->Command = array($firtCommand, $secondCommand, $thirdCommand);
// and execute all command
$data = $client->GetData();
// output results
echo '<pre>';
foreach ($data as $table)
{
print_r($table);
}
echo '</pre>';
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.