Skip to content

abthahiahmed/easybasephp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

EasyBase 1.0

EasyBase is a simple PHP library to use MySQL Database very easily

This library will minified the code for database operations in web applications. I am working on it. It will be more useful for PHP Web Developers.

These are simple example below :

Example : To initialize all the cradentials for database connection.

include 'eazybase.php';
$base = new EazyBase("localhost", "root", "12345678");


Example : To connect with database

if ($base->connect()){
	echo "Connected!<br>";
}else{
	echo "Not Connected!<br>";
}


Example : To create database

if ($base->createBase("mytest")){
	echo "Database Created!";
}else{
	echo "Database Not Created!";
}


Example : To drop a database

if ($base->deleteBase("mytest")){
	echo "Database Deleted!";
}else{
	echo "Database Not Deleted!";
}


Example : To import sql files to newly created database

if ($base->importToBase("./filename.sql")){
	echo "Database imported!";
}else{
	echo "Database not imported!";
}


Example : To create table

$result = $base->createTable("users", [ // Table Name
	'id' => 'int not null auto_increment', //// Column name => Data type with Auto increament
	'name' => 'varchar(255)', // Column name => Data type
	'email' => 'varchar(255)', // Column name => Data type
	'password' => 'varchar(255)', // Column name => Data type
],'id'); // Primary key


Example : To add column to table

// Single
$base->addColumn("mytest", [
	'column_name' => 'data_type'
]);

// Multiple
$base->addColumn("mytest", [
	'column_name1' => 'data_type',
	'column_name2' => 'data_type',
	'column_name3' => 'data_type',
]);


Example : To modify data type of column

// Single
$base->changeColumn("mytest", [
	'column_name' => 'data_type'
]);

// Multiple
$base->changeColumn("mytest", [
	'column_name1' => 'data_type',
	'column_name2' => 'data_type',
	'column_name3' => 'data_type',
]);


Example : To rename column

// Single
$base->renameColumn("mytest", [
	'old_name' => 'new_name'
]);

// Multiple
$base->renameColumn("mytest", [
	'old_name' => 'new_name',
	'old_name' => 'new_name',
	'old_name' => 'new_name',
]);


Example : To delete column

// Single
$base->deleteColumn("mytest", [
	'column_name'
]);

// Multiple
$base->deleteColumn("mytest", [
	'column_name1',
	'column_name2',
	'column_name3',
]);


Example : To delete table

$base->deleteTable("mytest");


Example : To insert data into table

$base->insert("users", [// Table Name
	'name' => 'myname', //Column => Data
	'email' => "email@gmail.com", //Column => Data
	'password' => '87654321' //Column => Data
]);


Example : To insert multiple data into table

$base->insertMore("users", [ //Table Name
	[
		'name' => 'Ehsan', //Column => Data
		'email' => "email1@gmail.com", //Column => Data
		'password' => '87654321' //Column => Data
	],
	[
		'name' => 'Abthahi', //Column => Data
		'email' => "email2@gmail.com", //Column => Data
		'password' => '87654321' //Column => Data
	],
	[
		'name' => 'Ishmam', //Column => Data
		'email' => "email3@gmail.com", //Column => Data
		'password' => '87654321' //Column => Data
	],
	[
		'name' => 'Sakib', //Column => Data
		'email' => "email4@gmail.com", //Column => Data
		'password' => '87654321' //Column => Data
	],
]);

Example : To select data from table

$data = $base->select("users", [], [], [], []);
echo "<pre>";
print_r($data);
echo "</pre>";


Example : To select data from table with specific column

$data = $base->select("users", ['name', 'email'], [], [], []);
echo "<pre>";
print_r($data);
echo "</pre>";


Example : To select data from table with condition

$data = $base->select("users", ['name', 'email'], [], [], [	
	'email' => ['=', 'email@gmail.com'], // Column => [Operator, Data]
]);
echo "<pre>";
print_r($data);
echo "</pre>";


Example : To select data from table with sorting

$data = $base->select("users", ['name', 'email'], ['ASC', 'id'], [], [	
	'email' => ['=', 'email@gmail.com'],// Column => [Operator, Data]
]);
echo "<pre>";
print_r($data);
echo "</pre>";


Example : To select data from table with limitation

$data = $base->select("users", 
	['name', 'email'], // Fields
	['ASC', 'id'], // Ordering Column
	[0, 50], // Limit
	[	
	'email' => ['=', 'email@gmail.com'], // Column => [Operator, Data]
]);
echo "<pre>";
print_r($data);
echo "</pre>";


To select data with logical operator like and/or :

$data = $base->select("users", [], ['ASC', 'id'], [0, 60], [
	'or' => [ // Logic Operator
		'name' => ['=', 'Abthahi'],	// Column => [Operator, Data]
		'email' => ['=', 'email30@gmail.com'],	// Column => [Operator, Data]
	],
	'and' => [ // Logic Operator
		'name' => ['=', 'Abthahi'],	// Column => [Operator, Data]
		'email' => ['=', 'email30@gmail.com'],	// Column => [Operator, Data]
	],
]);
echo "<pre>";
print_r($data);
echo "</pre>";


Example : To update data in a table

$base->update("users", [
	'name' => 'New Name'// Column => Data
], [
	'name' => ['=', 'Current Name'] // Column => [Operator, Data]
]);


Example : To delete data from table

// With equal operator (=)
$base->delete("users", [
	'id' => ['=', 1]]// Column => [Operator, Data]
]);
// With in operator (in)
$base->delete("users", [
	'id' => ['in', [1, 2, 3]]// Column => [Operator, Data(Array)]
]);


Example : To get last inserted id of table

	echo "Last ID : " . $base->lastInsertID(); // Return last inserted ID


Example : To close database connection

	$base->close(); // Close Connection

This is simple project which can help you to build PHP applications faster. Happy Coding...

About

You can write query code faster in PHP using it without any confusion.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages