PHP code example of samuelfaj / class_db

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

    

samuelfaj / class_db example snippets



     new ClassDb\Db(array(
        'host'     => 'localhost'      ,  // string - Host of Connection.
        'user'     => 'username'       ,  // string - Database's User.
        'password' => 'mysecretpass'   ,  // string - User's Password.
        'database' => 'myapplication'  ,  // string - Default Database name.
        'db_type'  => 'mysql'          ,  // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
    ));

    $sql = new ClassDb\Query($db);


     new ClassDb\Db(array(
        'host'     => 'localhost'      ,  // string - Host of Connection.
        'user'     => 'username'       ,  // string - Database's User.
        'password' => 'mysecretpass'   ,  // string - User's Password.
        'database' => 'myapplication'  ,  // string - Default Database name.
        'db_type'  => 'mysql'          ,  // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
    ));

    $sql = new ClassDb\Query($db);
    $sql->exec("SELECT * FROM users");
    var_dump($sql->query);


    = new ClassDb\Query(array(
        'host'     => 'localhost'      ,  // string - Host of Connection.
        'user'     => 'username'       ,  // string - Database's User.
        'password' => 'mysecretpass'   ,  // string - User's Password.
        'database' => 'myapplication'  ,  // string - Default Database name.
        'db_type'  => 'mysql'          ,  // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
    ));

    $sql->table('users');
    $sql->limit(array(0,10));
	
    var_dump($sql->select());


    = new ClassDb\Query($db);
    $sql->table('users');
    $sql->where(
        array('id'    , $_POST['id']),
        array('email' , $_POST['email'])
    );
    $sql->order('id','DESC');
    $sql->limit(1);

    if( $sql->select()->have_rows ){ 
        $sql->update(array('active' => 0)); 
    }