Giter Club home page Giter Club logo

database's Introduction

Database (discontinued, please use PDO)

SugiPHP\Database is a lightweight interface for accessing databases.

DriverInterface

SugiPHP\Database\DriverInterface is the first level of abstraction. On this level there are several database drivers for different databases like MySQL, PosgreSQL, SQLite, etc. Each database driver that implements this interface is giving us the ability to use same functions to connect to the server and access the data in an uniform way. This includes few basic operations like:

  • open()
  • close()
  • query()
  • fetch()
  • escape() and several others.

On construction you can pass connection settings or a database handle. If a handle parameter is given it will be used, instead of creating new database connection. If a handle is a wrong type a SugiPHP\Database\Exception will be thrown. Note that no connection will be automatically established - it requires additional open() call.

open() method will throw an SugiPHP\Database\Exception if a connection problem occur.

close() method frees database handler. After closing connection you can make another one with open() method only if a connection settings are set on creation.

query() method is used for all CRUD routines. If a query fails the method will return FALSE. You can make additional call to the error() method to check what was wrong with the SQL query.

And finally one note. You can use these drivers directly, but since they are very lightweight, they are limited in what they do. Instead you should use SugiPHP\Database to access much more functionality.

SugiPHP\Database\Database

SugiPHP\Database\Database acts as a second level of abstraction. It uses DriverInterface drivers as a base and extends functionality.

  • construct providing a DriverInterface or the Database can factory itself giving one array as a parameter.
  • database connection is not established on creation. This give you ability to instantiate SugiPHP\Database very early in the application.
  • connection is automatically established when it's really necessary - first time when you execute any database operation.
  • database functions specific to the type of the server can be accessed via their original names.
  • on close() the database handle is freed

SugiPHP\Database\Exception

Each database has it's own exception, warning and error routines, so we need one standard way do deal with them. SugiPHP\Database\Exception defines an exception type:

  • internal_error - typically on SugiPHP\Database creation - missing or invalid parameters, wrong database driver type, invalid handles, etc.
  • connection_error - database connection errors
  • sql_error - errors in database queries
  • resource_error - errors while fetching data, etc. providing wrong resource, typically after mismatched SQL queries

database's People

Contributors

tzappa avatar sebcbi1 avatar sebtcho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.