Skip to content
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.

mimoudix/PHP-MySQL-Database-Class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started with PHP MySQL Database Class

PHP MySQL Database Class allows you to write less and do more.

Prerequisites

  • PHP >= 5.5
  • PHP extensions (mysqli)

Installation

  1. Prepare your MySQL database

  2. Clone the repo

    git clone https://github.com/MimoudiX/PHP-MySQL-Database-Class.git
  3. Enter your database informations in config/config.php

    $database_connection->server = 'localhost';
    $database_connection->username = 'root';
    $database_connection->password = '';
    $database_connection->name = 'dbname';

Usage

Include bootstrap.php in your php file

include_once 'bootstrap.php';

Let's pretend we have a table called pages

page_id title url description
INSERT

The following PHP inserts a new record in pages table:

insert($table, $data = [], $clean = true)
//$clean is true by default, turn it false if you want to avoid cleaning strings
Database::insert('pages', ['title' => 'title here', 'url' => 'url here', 'description' => 'description here'], false);

The selection from the pages table will now look like this:

page_id title url description
1 title here url here description here
DELETE

The following PHP deletes a record in pages table where page_id is 1:

delete($from, $conditions = [])
Database::delete('pages', ['page_id' => '1']);
//you can write more conditions
Database::delete('pages', ['page_id' => '1',"title" => "title here"]);
//all conditions must be true or the record won't be identified
UPDATE

The following PHP will update title value in pages table where page_id is 1:

update($what, $fields = [], $conditions = [])
Database::update('pages', ['title' => 'new title here'], ['page_id' => '1']);

The selection from the pages table will now look like this:

page_id title url description
1 new title here url here description here
EXISTS

The following PHP will check if page_id exists in pages table where title == some title

exists($what = [], $from, $conditions = [])
if(Database::exists('page_id', 'pages', ['title' => 'some title'])) {
echo "page found";
} else {
echo "page not found";
}
SIMPLE GET

The following PHP will get title value where page_id is 1

simple_get($raw_what, $from, $conditions = [])
$title = Database::simple_get('title', 'pages', ['page_id' => 1]);
echo $title;
//will print "new title here"
GET

The following PHP is the same but will be capable of getting multiple values

get($what = [], $from, $conditions = [], $order = false, $clean = false)
$data = Database::get(['title', 'description'], 'pages', ['page_id' => 4]);

echo $data->title . "\n" . $data->description;
//will print new title here description here

you can also try * to get all values

$data = Database::get(['*'], 'pages', ['page_id' => 1]);
echo $data->page_id . $data->title . $data->url . $data->description;

Contact

MimoudiX - @MimoudiX - [email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages