PHP code example of syamsoul / php-db-wow

1. Go to this page and download the library: Download syamsoul/php-db-wow 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/ */

    

syamsoul / php-db-wow example snippets



use SoulDoit\PhpDBWow\DB;



$db = new DB($hostname, $db_name, $db_username, $db_password);


$hostname = 'localhost';

// or

$hostname = 'mysql.hostinger.my';

$db_name = 'new_project_db';

$db_username = 'root';

$db_password = 'mypassword';


// Autoload files using the Composer autoloader.
st', 'test_blank', 'root', '');
  

// *******
// INSERT
// *******

$table="shoes";

$parameters = [
    "brand" => "Lee",
    "price" => 543.23
];

$result = $db->insert($table, $parameters);

if($result === false) echo "Failed";
else echo "Success! The inserted ID is ".$result;
  
  

// *******
// DELETE
// *******

$table="shoes";

$conditions = [
    "id" => 2,
];

if($db->delete($table, $conditions) === false) echo "Failed";
else echo "Success! The item is deleted";

  

// *******
// UPDATE
// *******

$table="shoes";

$conditions = [
    "id" => 3,
];

$parameters = [
    "brand" => "Puma",
];

if($db->update($table, $conditions, $parameters) === false) echo "Failed";
else echo "Success! The item is updated";

  

// *******
// SELECT SINGLE DATA
// *******

$table = "shoes";

$conditions = [
    "id" => 3,
];

$data = $db->select($table, $conditions)->first();

if($data === false) echo "Failed";
else {
    echo "Success! \n";
    echo "Return Data: " . $data['brand'];
}


// *******
// SELECT MULTIPLE DATA
// *******

$table = "shoes";

$conditions = [
    "is_for_sale" => 1,
];

$data = $db->select($table, $conditions)->get();

if($data === false) echo "Failed";
else {
    echo "Success! \n\n";

    echo "Return Data: \n";
    foreach($data as $key => $each_data){
        echo $key . "=" . $each_data["brand"] . "\n";
    }
}
  
  

// *******
// SELECT USING RAW QUERY
// *******

$raw_sql_query = "SELECT * FROM `shoes` ORDER BY `id` DESC";

$query = $db->execute($raw_sql_query);

if($query === false) echo "Failed";
else {
    echo "Success! \n\n";

    echo "Return Data: \n";
    foreach($query->get() as $key => $each_data){
        echo $key . "=" . $each_data["brand"] . "\n";
    }
}

  

// *******
// OTHERS RAW QUERY
// *******

$raw_sql_query = "INSERT INTO `shoes` (`brand`, `price`) VALUES ('Adidas', 432.43)";

if($db->execute($raw_sql_query) === false) echo "Failed";
else echo "Success!";

 bash

composer