A complete, simple and powerful database framework written in PHP

Overview

BaseSQL

BaseSQL is a complete database framework written in PHP. It was built to accelerate projects development by handle database connections and queries in a simple yet powerful way.

Build Packagist License Release

Features

  • DBMS supported: MySQL, SQLite, PostgreSQL
  • Security: Prevents SQL injection
  • Difficulty: Simple to manage
  • Price: Free usage under the MIT license
  • Modeling: Design patterns and SOLID principles

Install via composer

Add BaseSQL to composer.json configuration file.

composer require willpinha/basesql

And update the composer.

composer update

Documentation

The full documentation can be found here.

Quick start

Require composer autoload and use the main class BaseSQL.

require_once("vendor/autoload.php");

use BaseSQL\BaseSQL;

Connect to a database

The BaseSQL class receives a single constructor argument indicating the DBMS you want to access.

$basesql = new BaseSQL("mysql");

Choosing the database type directly affects which instances will be returned by the BaseSQL object's methods.

$conn = $basesql->createConnection([
  "hostname" => "...",
  "username" => "...",
  "password" => "...",
  "database" => "..."
]);

In our example, since we choose MySQL as our DBMS, the variable $conn will be a MySQL Connection object.

Build queries

The Query class is in charge of building and parsing SQL expressions. To get a Query instance based on the DBMS choosen, you should call the BaseSQL createQuery() method.

$sql = $basesql->createQuery();

Lets build an insert query and get its translation.

// building insert query
$sql->insert()
    ->into("table")
    ->values([
      "columnA" => "valueA",
      "columnB" => "valueB"
    ]);
    
// getting query translation/result
$translation = $sql->translate();

$paramQuery = $translation->getParamQuery(); // string
$args = $translation->getArgs();             // array
$isWriteType = $translation->isWriteType();  // boolean

The Query class supports almost every SQL expression, even the unique expressions a particularly DBMS has.

Run queries

After building a query, you can run it through a Connection object.

$sql = $basesql->createQuery();

$sql->update("table")
    ->set([
      "column" => "newValue"
    ])
    ->where("column", "=", "oldValue");
    
$result = $conn->query($sql);

The query() method will return different values depending on the query type:

  • Write-type queries (like INSERT, UPDATE, DELETE) will return true on success and false otherwise.

  • Read-type queries (like SELECT) will return a QueryResult instance that can be used to get information from the database.

Get results

Lets build a read-type query and get its results.

$sql = $basesql->createQuery();

$sql->select(["columnA", "columnB", "columnC"])
    ->from("table")
    ->where("columnA", "LIKE", "%somevalue")
    ->andWhere("columnB", "=", "othervalue");
    
$result = $conn->query($sql);
You might also like...
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Phpstan-dba - database handling related class reflection extension for PHPStan & framework-specific rules

database handling class reflection extension for PHPStan This extension provides following features: PDO-query knows the array shape of the returned

Tablavel - A simple Database Client for Laravel

Tablavel - A simple Database Client for Laravel Table of Contents About Getting Started Usage Contributing About This solves a simple problem. Know th

Orm is a simple database abstraction layer that supports postgresql.

Orm What is it Orm is a simple database abstraction layer that supports postgresql. Welcome to join us or star us for encouragement. Requires php 8.1

RockMongo is a MongoDB administration tool, written in PHP 5.

Introduction -------------------------------------- RockMongo is a MongoDB administration tool, written in PHP 5, very easy to install and use. Inst

Clean up your Magento database by removing orphaned, unused and wrongly added attribute, attribute values and settings (for M2).

Magento 2 EAV Cleaner Console Command Purpose of this project is to check for different flaws that can occur due to EAV and provide cleanup functions.

A php class for managing and connecting to a database

Query builder class php This class is responsible for creating and executing sql commands and helps you to execute as easily as possible and safely. I

ORM layer that creates models, config and database on the fly

RedBeanPHP 5 RedBeanPHP is an easy to use ORM tool for PHP. Automatically creates tables and columns as you go No configuration, just fire and forget

Releases(v1.0.0)
Owner
Willian Pinheiro
Willian Pinheiro
phpSleekDBAdmin - a web-based SleekDB database admin tool written in PHP

phpSleekDBAdmin is a web-based SleekDB database admin tool written in PHP. Following in the spirit of the flat-file system used by SleekDB, phpSleekDBAdmin consists of a single source file, phpsleekdbadmin.php. The interface and user experience is comparable to that of phpLiteAdmin and phpMyAdmin.

GalAnonym 8 Oct 26, 2022
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

SleekwareDB 12 Dec 11, 2022
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.

Please give it a Star if you like the project ?? ❤️ SleekDB - A NoSQL Database made using PHP Full documentation: https://sleekdb.github.io/ SleekDB i

Kazi Mehedi Hasan 745 Jan 7, 2023
Connect and work with MySQL/MariaDB database through MySQLi in PHP. This is an introductory project, If you need a simple and straightforward example that takes you straight to the point, you can check out these examples.

First MySQLi PHP Connect and work with MySQL/MariaDB database through MySQLi in PHP. The above exercises are designed for students. This is an introdu

Max Base 4 Feb 22, 2022
This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FTP, SFTP, and Rackspace Cloud

Database Backup Manager This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FT

Backup Manager 1.6k Dec 23, 2022
The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

Mark Armendariz 0 Jan 7, 2022
A simple library to access and manipulate database records. Built on top of Dibi and hardwired for PostgreSQL.

grifart/tables A simple library to access and manipulate database records. Built on top of Dibi and hardwired for PostgreSQL. This library is develope

GRIFART 5 Nov 11, 2022
A simple library for managing database connections, results pagination and building queries in PHP

PHP lions-software-database-manager This is a simple library for managing database connections, results pagination and building queries in PHP. Esta é

Lions Software 0 Feb 7, 2022
The lightweight PHP database framework to accelerate development

The lightweight PHP database framework to accelerate development Features Lightweight - Less than 100 KB, portable with only one file Easy - Extremely

Angel Lai 4.6k Dec 28, 2022
[READ-ONLY] A flexible, lightweight and powerful Object-Relational Mapper for PHP, implemented using the DataMapper pattern. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP ORM The CakePHP ORM provides a powerful and flexible way to work with relational databases. Using a datamapper pattern the ORM allows you to m

CakePHP 146 Sep 28, 2022