-
Notifications
You must be signed in to change notification settings - Fork 291
Installation
The following instructions outlines how to get started with ezSQL.
From here it is recommended to check out the quick examples, or if you want more details the detailed examples in the documentation.
Note: Composer is required for version 4/5. Head to the composer website if you don't already have it installed.
composer require ezsql/ezsql
Default initialization
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
$db = Database::initialize('****', [user, password, database, other settings], **optional tag);
You can also initialize your database with the following alternative initialization
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Config; // Load ezSQL Config Class
use ezsql\Database\ez_****; // Load ezSQL driver Class
$settings = new Config('****', [user, password, database, other settings]);
$db = new ez_****($settings);
Note: **** is one of mysqli, pgsql, sqlsrv, sqlite3, or pdo.
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - DB_USER, DB_PASSWORD, DB_NAME
$db = Database::initialize('mysqli', ['ezsql_user', 'ezsql_password123', 'ezsql_database']);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - DB_HOST/DB_NAME/DB_CHARSET, DB_USER, DB_PASSWORD
$db = Database::initialize('pdo', ['mysql:host=localhost;dbname=ezsql_database;charset=utf8', 'ezsql_user', 'ezsql_password123']);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - DB_HOST/DB_NAME/DB_CHARSET, DB_USER, DB_PASSWORD
$db = Database::initialize('pdo', ['pgsql:host=localhost;dbname=ezsql_database;charset=utf8', 'ezsql_user', 'ezsql_password123']);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - SQLITE_DB
$db = Database::initialize('pdo', ['sqlite:./db/ezsql_database.sqlite', '', '', array(), true]);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - DB_HOST/DB_NAME, DB_USER, DB_PASSWORD
$db = Database::initialize('pdo', ['sqlsrv:Server=localhost;Database=ezsql_database', 'ezsql_user', 'ezsql_password123']);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - DB_USER, DB_PASSWORD, DB_NAME, DB_HOST, DB_PORT
$db = Database::initialize('pgsql', ['ezsql_user', 'ezsql_password123', 'ezsql_database', 'localhost', '5432']);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - SQLITE_DB_DIR, SQLITE_DB
$db = Database::initialize('sqlite3', ['./db/ezsql_database/', 'ez_test.sqlite3']);
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
use ezsql\Database; // Load ezSQL Database Class
// FORMAT - DB_USER, DB_PASSWORD, DB_NAME
$db = Database::initialize('sqlsrv', ['ezsql_user', 'ezsql_password123', 'ezsql_database']);
More detailed examples can be found in the tests folder
Note: Composer is not required for version 3.x, but it is recommended.
composer require ezsql/ezsql=^3.1.2
Default initialization Using Composer
<?php
require 'vendor/autoload.php'; // Needed to load composer autoloader
$db = new ezSQL_****(user, password, database, or, other settings);
Alternative initialization manually downloading
Manually download https://github.com/ezSQL/ezSQL/archive/v3.zip and extract it to your required web directory.
<?php
require 'ez_sql_loader.php'; // Require path to where you extracted your ezSQL v3 file
$db = new ezSQL_****(user, password, database, or, other settings);
Note: **** is one of mysqli, pgsql, sqlsrv, sqlite3, or pdo.
Note: Version 2 is barely supported. Some of the documentation still references part of it though so here are some notes.
$db = new db -- Initiate new db object. Connect to a database server. Select a database.
$db = new db(string username, string password, string database name, string database host)
Does three things. (1) Initiates a new db object. (2) Connects to a database server. (3) Selects a database. You can also re-submit this command if you would like to initiate a second db object. This is interesting because you can run two concurrent database connections at the same time. You can even connect to two different servers at the same time if you want to.
Note: For the sake of efficiency it is recommended that you only run one instance of the db object and use $db->select to switch between different databases on the same server connection.
Example
<?php
// Initiate new database object.
$db2 = new db(”user-name”, ”user-password”, ”database-name”, “database-host”); // version 2 and 3
// Perform some kind of query..
$other_db_tables = $db2->get_results(“SHOW TABLES”);
// You can still query the database you were already connected to..
$existing_connection_tables = $db->get_results(“SHOW TABLES”);
// Print the results from both of these queries..
$db->debug();
$db2->debug();