PHP code example of johannmalmcom / database
1. Go to this page and download the library: Download johannmalmcom/database library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
johannmalmcom / database example snippets
use Database\MySQL;
// Connection
$database = new MySQL();
$database->setServer("127.0.0.1");
$database->setUsername("your_username");
$database->setPassword("your_password");
$database->setDatabase("your_dbname");
// Create table
$database->createTable("users", [
$database->typeString("email"),
$database->typeString("password", 40),
$database->typeString("token", 40)
]);
// Insert data
$database->insertInto("users", [
"email" => "[email protected] "
]);
// Update data
$database->update("users", [
"password" => sha1("1234")
], [
"id" => 1
]);
// Delete data
$database->deleteFrom("users", 5);
// Select data
$database->selectFrom("users", [
"email" => "[email protected] "
]);
// Search data
$database->searchFrom("users", [
"created_at" => "20"
]);
// Handle responses
if ($database->getError() !== null) {
exit($database->getError());
}
print_r($database->getResult());