PHP code example of lazarusphp / querybuilder

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

    

lazarusphp / querybuilder example snippets


composer 


namespace App\Http\Model;

class Users extends Model
{

}

namespace App\Http\Controllers;
use App\Http\Model\Users;
class HomeController
{
    public function index()
    {
        $users = new Users();
    }
}


  public function index()
    {
        $users = new Users();
        $users->select()->get();
    }

  public function index()
    {
        $users = new Users();
        $users->select()->first();
    }

  public function index()
    {
        $users = new Users();
        $users->select("username","email","password","firstname","lastname")->get();
    }


 public function index()
    {
        $users = new Users();
        $users->select("u.username")->as("u")->where("u.username","mrbean")->save();
    }

 public function insert()
    {
        $users = Users();
        $users->username = "mrbean";
        $users->password = password_hash("test",PASSWORD_DEFAULT);
        // using save is no longer needed
        $users->insert();
        // optionally data can be passed as an array value
        $users->insert(["username"=>"mrbean"]);
    }

public function insert()
{
    $users = new Users();
    $users->username = "mrbean";
    $users->insert();
    // this will only be visable with insert.
    echo $users->lastId;
}

 public function update()
    {
        $users = new Users();
        $users->username = "mrbean";
        $users->password = password_hash("Apple12345",PASSWORD_DEFAULT);
        $users->update()->where("id",1)->save();
    }

 public function delete()
    {
        $users = new Users();
        $users->delete()->where("id",1)->save();
    }


// Adding a table is currently >select()->as("u")->where("u.username","mrbean")->get();