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 :
include 'eazybase.php';
$base = new EazyBase("localhost", "root", "12345678");
if ($base->connect()){
echo "Connected!<br>";
}else{
echo "Not Connected!<br>";
}
if ($base->createBase("mytest")){
echo "Database Created!";
}else{
echo "Database Not Created!";
}
if ($base->deleteBase("mytest")){
echo "Database Deleted!";
}else{
echo "Database Not Deleted!";
}
if ($base->importToBase("./filename.sql")){
echo "Database imported!";
}else{
echo "Database not imported!";
}
$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
// Single
$base->addColumn("mytest", [
'column_name' => 'data_type'
]);
// Multiple
$base->addColumn("mytest", [
'column_name1' => 'data_type',
'column_name2' => 'data_type',
'column_name3' => 'data_type',
]);
// Single
$base->changeColumn("mytest", [
'column_name' => 'data_type'
]);
// Multiple
$base->changeColumn("mytest", [
'column_name1' => 'data_type',
'column_name2' => 'data_type',
'column_name3' => 'data_type',
]);
// Single
$base->renameColumn("mytest", [
'old_name' => 'new_name'
]);
// Multiple
$base->renameColumn("mytest", [
'old_name' => 'new_name',
'old_name' => 'new_name',
'old_name' => 'new_name',
]);
// Single
$base->deleteColumn("mytest", [
'column_name'
]);
// Multiple
$base->deleteColumn("mytest", [
'column_name1',
'column_name2',
'column_name3',
]);
$base->deleteTable("mytest");
$base->insert("users", [// Table Name
'name' => 'myname', //Column => Data
'email' => "email@gmail.com", //Column => Data
'password' => '87654321' //Column => Data
]);
$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
],
]);
$data = $base->select("users", [], [], [], []);
echo "<pre>";
print_r($data);
echo "</pre>";
$data = $base->select("users", ['name', 'email'], [], [], []);
echo "<pre>";
print_r($data);
echo "</pre>";
$data = $base->select("users", ['name', 'email'], [], [], [
'email' => ['=', 'email@gmail.com'], // Column => [Operator, Data]
]);
echo "<pre>";
print_r($data);
echo "</pre>";
$data = $base->select("users", ['name', 'email'], ['ASC', 'id'], [], [
'email' => ['=', 'email@gmail.com'],// Column => [Operator, Data]
]);
echo "<pre>";
print_r($data);
echo "</pre>";
$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>";
$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>";
$base->update("users", [
'name' => 'New Name'// Column => Data
], [
'name' => ['=', 'Current Name'] // Column => [Operator, Data]
]);
// 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)]
]);
echo "Last ID : " . $base->lastInsertID(); // Return last inserted ID
$base->close(); // Close Connection
This is simple project which can help you to build PHP applications faster. Happy Coding...