PHP code example of arthur-rmd / php-easy-sql

1. Go to this page and download the library: Download arthur-rmd/php-easy-sql 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/ */

    

arthur-rmd / php-easy-sql example snippets




exemple : 

class  DbConfig
{
	private  $configLink  = "../../config.json";
	...
}


Db::setLink('../../config.json');

DbConfig::getData(); 
// renvoie un tableau avec toutes les informations contenue dans le fichier config.json
//['sgbd' => 'mysql', 'serveur' => 'localhost', 'login' => 'root', 'pass','mot_de_passe' 'base' => 'nom_de_la_base']

DbConfig::getData('sgbd'); // renvoie 'mysql'

$link = DbConfig::getLink();
echo $link // renvoie la chaine "config.json"

DbConfig::setLink('../../config.json');

$pdo = DbConfig::getPdo();
$pdo->query('select * from users');

DbConfig::close();

Db::select('select * from users');
Db::select('select * from users where prenom like "Arthur"');

Db:query("insert into users values ('prenom') value ('Arthur') ");


Db::select('select * from users where prenom like :prenom',['prenom' => 'Arthur'] );

$var = 'Arthur';
Db:query("insert into users values ('prenom') value (:prenom) ", ['prenom' => $var]);


Db::selectAll('users');

Db::selectAll('users', ['prenom', '=', 'Arthur']);
Db::selectAll('users', ['prenom','Arthur']);
// Les deux résulat seront identique


Db::selectAll('users', ['id', '>', '10']);


Db::find('users', 5);
// est égale a la requête suivante
// select * from users where id = 5;

Db::delete('users', ['prenom', '!=', 'Arthur'] );

Db::insert( 'users', ['prenom' => 'Arthur', 'age' => 20, 'pays' => 'france']);

Db::update( 'users', ['prenom' => 'Arthur'], ['id', 5] ); 

//exemple:
self::select( ...);
self::find( ...);
 
class Db extends DbQuery  {

	public static function ageBetween($ageMin,$ageMax)
	{
		return self::select('select * from users where age > :ageMin and age < :ageMax', ['ageMin' => $ageMin, 'ageMax' => $ageMax]);
	}

}

Db::ageBetween(18,25);