simpledatabase/simple-database

Simple Database API for PHP and SQL

dev-master 2021-03-22 19:56 UTC

This package is auto-updated.

Last update: 2024-04-23 03:01:33 UTC


README

Introduction

Simple Database is a very simple PHP API for using an SQL-Database with only a few lines of code. Use a full working SQL database with only a few lines of code.

Code Samples

Full Documentation can be found here: https://docs.google.com/document/d/1eufGXHW__C4uOW9Lr9XoAAzOX8vFrd5qNAytYAM4VgQ/edit?usp=sharing

Connect to database

You can simply connect to your database using the following 2 lines of code.

$database = new Database("Your Servername", "Your Database User", "YourUserPassword", "YourDatabaseName");
$database->connect();

After connection the database is available in the variable $database.

Insert into database

You can also easily insert data into a database using 2 arrays. One array is for the row names, the other for the rows value

$row = ['name', 'description', 'price'];
$value = ['Soap', 'A nice soap', 5.95];
$if($database->insertRow('products', $row, $value)){
    echo "Succesfully added product to products. The insert id is: " . $database->getInsertId();
}

After inserting columns into the database as above, the last inserted id is available in $database->getInsertId();

Read from database

To read data from the database you need to use the $database->readAll(table) function.

$data = $database->readAll("products");
while($row = $data->fetch_assoc()){
    echo $row['name'];
}

In the example above we get all data from the database and fetch the data to the variable $row. After that we can return the row['name'] from the database.

Installation

To install this API you can simply download the files on this github and put it into your root directory. Enable the API by adding the following line of code at the top of your PHP file

require_once("config/database/database.php");