PHP code example of laykith / easyconnect

1. Go to this page and download the library: Download laykith/easyconnect 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/ */

    

laykith / easyconnect example snippets




use EasyConnect\EasyConnect;

//Example configs (Use what you need based on driver)
$config = [
    'driver'   => 'Sqlite',                              //MySQL SQLite pgsql - (Case Insensetive)
    'filepath' => 'absolute/path/to/database/file.db',   //pgsql
    'username' => 'root',                                //ite
    'host'     => getEnv('database_host'),       //

//Example query
$query = 'SELECT * FROM user';

//Params (Optional but highly advised to protect from SQL injections)
$params = [];

//Returns array of results
$result = $database->getData($query, $params);


//Insert data
//Query (Required)
$query = 'INSERT INTO user (username, password) VALUES (:username, :password)';

//Params (Optional but highly advised to protect from SQL injections)
$params = [
    ':username' => $_POST['username'],
    ':password' => password_hash($_POST['password'], PASSWORD_BCRYPT),
];

//Insert into Database
$database->setData($query,$params);

//Gets the error message if PDO exception was triggered.
$database->getError();