Skip to content
PHP DB Wow - Your life will be easier in handling MySQL database.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
LICENSE
README.md
composer.json

README.md

PHP DB Wow

Latest Version on Packagist

This package will make your life easier in handling MySQL database.

 

   

Requirement

  • PHP version: 5.5.0 and above

   

Installation

This package can be used in PHP 5.5 or higher. If you are using an older version of PHP, there's might be some problem. If there's any problem, you can create new issue and I will fix it as soon as possible.

You can install the package via composer:

composer require syamsoul/php-db-wow

   

Usage & Reference

* Before you read this section, you can take a look the example below to make it more clear to understand.

 

How to use it?

First, you must add this line to your Controller:

use SoulDoit\PhpDBWow\WowDB;

 

And then create a new WowDB instance:

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

Which is:

  • $hostname is a string of your server hostname, for example:
    $hostname = 'localhost';
    
    // or
    
    $hostname = 'mysql.hostinger.my';
  • $db_name is a string of your database name, for example:
    $db_name = 'new_project_db';
  • $db_username is a string of your MySQL's username, for example:
    $db_username = 'root';
  • $db_password is a string of your MySQL's password, for example:
    $db_password = 'mypassword';

 

And that's it. Now you have a connection with database. Congrats!

Next step is how to run the sql queries. Just head off to the example section and I'm sure you'll understand.

Enjoy! :D

   

Example

// Autoload files using the Composer autoloader.
require_once __DIR__ . '/vendor/autoload.php';

use SoulDoit\PhpDBWow\WowDB;

$db = new WowDB('localhost', 'test_blank', 'root', '');


// *******
// INSERT
// *******
$table="shoes";

$parameters=Array(
    "brand" => "Lee",
    "price" => 543.23
);

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

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




// *******
// DELETE
// *******
$table="shoes";

$conditions=Array(
    "id"    => 2,
);

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




// *******
// UPDATE
// *******
$table="shoes";

$conditions = Array(
    "id"    => 3,
);

$parameters = Array(
    "brand" => "Puma",
);

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





// *******
// SELECT
// *******
$table  = "shoes";

$conditions = Array(
    "id"    => 3,
);

if(!$db->select($table, $conditions)) echo "Failed";
else {
    echo "Success!";

    echo "<div>Return Data: </div>";
    echo "<ol>";
    foreach($db->multiData as $key=>$data){
        echo "<li>".$data["brand"]."</li>";
    }
    echo "</ol>";
}





// *******
// SELECT USING RAW QUERY
// *******
$sql_query = "SELECT * FROM `shoes` ORDER BY `id` DESC";

if(!$db->query($sql_query)) echo "Failed";
else {
    echo "Success!";

    echo "<div>Return Data: </div>";
    echo "<ol>";
    foreach($db->multiData as $key=>$data){
        echo "<li>".$data["brand"]."</li>";
    }
    echo "</ol>";
}




// *******
// OTHERS RAW QUERY
// *******
$sql_query = "INSERT INTO `shoes` (`brand`, `price`) VALUES ('Adidas', 432.43)";

if(!$db->query($sql_query)) echo "Failed";
else echo "Success!";

   

Support me

I am a passionate programmer. Please support me and I will continue to contribute my code to the world to make the world better. :')

Please make a donation. :')

#MalaysiaBoleh

   

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.