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/ */

    

aleksey.nemiro / nemiro.data.php example snippets


// MySql
define('MYSQL_DB_NAME', '%your database name here%');
define('MYSQL_DB_USER', '%your database username here%');
define('MYSQL_DB_PASSWORD', '%your database password here%');
define('MYSQL_DB_HOST', 'localhost');
define('MYSQL_DB_PORT', 3306);
define('MYSQL_DB_MODE', 2);

// PostgreSQL
define('PGSQL_DB_NAME', '%your database name here%');
define('PGSQL_DB_USER', '%your database username here%');
define('PGSQL_DB_PASSWORD', '%your database password here%');
define('PGSQL_DB_HOST', 'localhost');
define('PGSQL_DB_PORT', 5432);
define('PGSQL_DB_MODE', 1);





// 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>';