Database Library for PHP
INFORMATION
-----------------
The library is currently in the BETA-Phase!
Errors can happen, so if you found a bug, please let me know. You can contact me at the email address [email protected]; or via Twitter at https://www.twitter.com/SerumDev via Direct Message. Thanks!
<?php
use Library\Base\Database;
require_once('database/database.class.php');
$database = new Database("host e.g. localhost", port e.g. 3306, "user e.g. root", "password", "table");
?>
- You can create the database structure in the method "tableMatrix"; which is called automatically after a successful connection to the database.
-
Declaration:
Write into a table. -
Example:
Code: $database->writeNow("users", array("firstName", "lastName"), array("Max", "Mustermann")); Executed Query: INSERT INTO users("firstName", "lastName") VALUES(?, ?);
-
Declaration:
Delete a entry from the table -
Example:
Code: $database->delete("users", "firstName", "Max"); Executed Query: DELETE FROM users WHERE firstName=?;
-
Declaration:
Returns all entries from the table -
Example:
Code: $result = $database->queryAll("users"); print_r ($result); Executed Query: SELECT * FROM users; Output: Array ( [0] => Array ( [firstName] => Max [0] => Max [lastName] => Mustermann [1] => Mustermann [email] => [email protected] [2] => [email protected] ) )
-
Declaration:
Returns an object -
Example:
Code: $result = $database->query("users", "firstName", "Max"); print_r ($result); Executed Query: SELECT * FROM users WHERE firstName=?; Output: Array ( [firstName] => Max [0] => Max [lastName] => Mustermann [1] => Mustermann [email] => [email protected] [2] => [email protected] )
-
Declaration:
Returns an object where you can define 2 key and values -
Example:
Code: $result = $database->queryConditional("users", "firstName", "Max", "lastName", "Mustermann"); print_r ($result); Executed Query: SELECT * FROM users WHERE firstName=? AND lastName=?; Output: Array ( [firstName] => Max [0] => Max [lastName] => Mustermann [1] => Mustermann [email] => [email protected] [2] => [email protected] )
-
Declaration:
Execute a special query of whatever you want -
Example:
Code: $result = $database->querySpecial("SELECT table.uuid, round(table.kills/table.deaths) as kd FROM table ORDER BY kd LIMIT 10"); print_r ($result); Executed Query: SELECT table.uuid, round(table.kills/table.deaths) as kd FROM table ORDER BY kd LIMIT 10; Output: Get the top ten players based on the KD
-
Declaration:
Returns the count of all entries of the table -
Example:
Code: $result = $database->queryLength("users"); print_r ($result); Executed Query: SELECT COUNT(*) FROM users; Output: #n
-
Declaration:
Returns a number from the entered data -
Example:
Code: $result = $database->queryLengthWhere("users", "firstName", "Max"); print_r ($result); if ($result == 0) { // User not exist } else { // User exist } Executed Query: SELECT COUNT(*) FROM users WHERE firstName=?; Output: 0 || 1
-
Declaration:
Returns any values that start with the $value (pattern) -
Example:
Code: $result = $database->queryLike("users", "firstName", "a%"); print_r ($result); Executed Query: SELECT * FROM $table WHERE firstName LIKE ?; Output: Returns any values that start with "a" as array
-
Declaration:
Execute a command in the current database -
Example:
Code: $this->invokeCommand("CREATE TABLE IF NOT EXISTS test(firstName VARCHAR(256), lastName VARCHAR(256), email VARCHAR(256));"); Executed Query: CREATE TABLE IF NOT EXISTS test(firstName VARCHAR(256), lastName VARCHAR(256), email VARCHAR(256));