PHP code example of scrawler / arca

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

    

scrawler / arca example snippets


   
    nnectionParams = array(
        'dbname' => 'YOUR_DB_NAME',
        'user' => 'YOUR_DB_USER',
        'password' => 'YOUR_DB_PASSWORD',
        'host' => 'YOUR_DB_HOST',
        'driver' => 'pdo_mysql', //You can use other supported driver this is the most basic mysql driver
    );

    
    $db = \Scrawler\Arca\Facade\Database::connect($connectionParams);

   //If you dont want to use facade , directly build from factory
   $factory =  \Scrawler\Arca\Factory\DatabaseFactory()
   $db = $factory->build($connectionParams)
    


    // Create new record
    // The below code will automatically create user table and store the record

    $user = $db->create('user');
    $user->name = "Pranja Pandey";
    $user->age = 24
    $user->gender = "male"
    $user->save()
    
    // Get record with id 1
    
    $user = $db->getOne('user',1);
    
    //Get all records
    
    $users = $db->get('user');
    
    // Update a record
     $user = $db->getOne('user',1);
     $user->name = "Mr Pranjal";
     $user->save();
     
    // Delete a record
     $user = $db->getOne('user',1);
     $user->delete();



  // Using where clause
  $users = $db->find('user')
              ->where('name = "Pranjal Pandey"')
              ->get();
 // If where input in unsafe or user defined
 $name = "Pranjal"
 $users = $db->find('user')
              ->where('name = ?')
              ->setParameter(0,$name)
              ->get();
              
  foreach ($users as $user){
  // Some logic here 
  }
  
  // Get only single record
  $users = $db->find('user')
             ->where('name = "Pranjal Pandey"')
             ->first();  

  // Using limit in query
  $users = $db->find('user')
              ->setFirstResult(10)
              ->setMaxResults(20);
              ->get()