-
Notifications
You must be signed in to change notification settings - Fork 1
Database
Jeroen edited this page Jan 11, 2016
·
2 revisions
This document aims to make the Quantiweb database system as easy to understand as posible.
All values with a * are required
####Index
db_select
db_custom
db_grab
db_numrows
db_insert
db_update
db_delete
db_create
db_escape
db_array_escape
db_entry_exist
$select = new Select($tablename);
Arguments:
- $tablename*: string, the name of the table you want to select from.
In this example we want to get all active plugins.
``` php where("setting", "plugins"); $select->limit(1); $select->order("setting DESC"); $select->execute(); ?> ```
db_custom($query);
- $query: String, the sql query you want to run.
<?php
$query = "SELECT * FROM system_settings";
$result = db_custom($query);
while($row = db_grab($query)){
echo $row['value'];
}
?>
Warning: You can NOT delete tables or databases with db_custom(). Use db_delete().
db_grab($query);
See db_select for usage.
db_numrows($query);
see db_select for $query usage.
Example:
<?php
$query = db_select("*", "system_settings");
echo db_numrows($query);
//This will echo the number of results of the query.
?>
db_insert($table, $values);
- $table*: String, The table you want to insert the data.
- $values*: Array, The data you want to insert.
``` php "value" ); db_insert($table, $array); ?> ```
db_update($table, $set, $where);
- $table*: String, The table you want to insert the data.
- $values*: Array, The data you want to insert.
- $where: Array
$where = array("collumn_name" => "my value");
``` php "value" ); $where = array( "another_collumn_name" => "another_value" ); db_update($table, $set, $where); ?> ```
db_delete($from, $where, $verification)
db_delete will give your plugin a low ranking!
- $table*: String, The table you want to insert the data.
- $where*: Array
$where = array("collumn_name" => "my value");
- $verification*: Integer, 1 or 0. If int is 0 the query will NOT work. You can use this to make a user-dialog for example.
``` php "another_value" ); $verification = 1; db_delete($table, $where, $verification); ?> ```
db_create($table, $attributes, $primary_key);
- $table*: String, The table you want to insert the data.
- $attributes: Array
$attributes = array("collumn_name" => "type, e.g. TEXT or INT and extra info e.g. DEFAULT null");
- $primary_key: String, collumn_name of primary key.
``` php $attributes = array( "title" => "TEXT", "content" => "TEXT" "content_id" => "INT NOT NULL AUTO_INCREMENT" ); $primary_key = "content_id"; db_create($table, $attributes, $primary_key); ?> ```
db_escape($string);
- $string*: String, The string you want to escape
``` php ```
db_array_escape($array, $key);
- $array*: Array, The array you want to escape
- $key: Integer, set to 1 if you want to escape a 3d array
``` php ```
Example with key:
<?php
$array = array(
"world1!" => "Hello world!",
"world2!" => "H@llo W()rld"
);
$newarray = db_array_escape($array);
/*This will return
$array = array(
"world1\!" => "Hello world\!",
"world2\!" => "H@llo W\(\)rld"
);
*/
?>
db_entry_exist($table, $where);
This will return the
db_numrows()
value without the need of a separate query.
db_table_exist($table)
- $table: String, name of a table
In this example we want to create a table, if it doens't already exists.
``` php ```