Simon's MySQL

Česky View on GitHub

How to run extension

First include extension file with include command.
Then create object of extension. If the parameters are missing, this extension will use defaults from php.ini. Syntax:
new Smysql([string $host = NULL, string $user = NULL, string $password = NULL[, string $database = NULL]])
Or:
Smysql([string $host = NULL, string $user = NULL, string $password = NULL[, string $database = NULL[, &$object]]])
host
- Server address.
user
- Username.
password
- Password.
database
- Database name. Write create[database name] to create database.
object
- Empty or undefined object, if it's mentioned, method won't return anything and object of extension will be saved in this variable.
Or:

              class mySmysql extends Smysql {
                protected $host = "Server address";
                protected $user = "Username";
                protected $password = "Password";
                protected $db = "Database name";
              };
              $object = new mySmysql();
            
Return value:
Object of extension.

Charset

This method sets character set. Syntax:
$object->charset(string $charset)
object
- Object of extension.
charset
- Charset(E. G.: utf8, latin1, latin2, utf8mb4, utf16, utf16le, cp1250, ascii. You will find complete list of charsets on this site.)

Escape

This method escapes all dangerous characters. Syntax:
$object->escape(string $string)
object
- Object of extension.
string
- Text.
Return value: Escaped text.

Query

This method executes SQL query. Syntax:
$object->query(string $sqlCommand)
object
- Object of extension.
sqlCommand
- SQL query.
Return value:
MySQL code of resuult.

ChangeDB

This method changes selected database. Syntax:
$object->changeDB(string $database)
Object
- Object of extension.
Database
- Database name. Write create[database name] to create new database.

DeleteDB

This method deletes database. Syntax:
$object->deleteDB(string $database[, string $close = false])
Object
- Object of extension.
Database
- Database to delete.
Close
- If it's true connecting will closed.
Return value: This method returns TRUE in case of success, else it returns FALSE.

CreateTable

This method creates table. Syntax:
$object->createTable(string $table, array $names, array $types, array $lenghts[, string $primary = NULL[, array $uniques = array()[, array $others = array()]]])
Object
- Object of extension.
Table
- Table name.
Names
- Array of column names.
Types
- Array of column types (int or bigint for number, varchar for text...).
Lengths
- Array of maxlenghts, in case of INT type, value can be empty.
Primary
- Name of column, which will have PRIMARY key.
Uniques
- Array of column names, which will have UNIQUE key.
Others
- Array of additional parameters of columns, E. G. A_I.

RenameTable

This method renames table. Syntax:
$object->renameTable(string $table, string $newName)
Object
- Object of extension.
Table
- Old table name.
NewName
- New table name.

DeleteTable

This method deletes table. Syntax:
$object->deleteTable(string $table)
Object
- Object of extension.
Table
- Name of the table to delete.

Fetch

This method returns object from the last database result. Syntax:
$object->fetch([$result])
Object
- Object of extension.
Result
- Database result, if it's not mentioned, this method will use result from last call of method select, selectWhere, selectJoin, exists, queryf or query.
Return value: This method returns object with values of current row of table.

FetchArray

This method returns array with values of current row of table. Syntax:
$object->fetchArray([$result])
Object
- Object of extension.
Result
- Database result, if it's not mentioned, this method will use result from last call of method select, selectWhere, selectJoin, exists, queryf or query.
Return value: This method returns array with values of current row of table.

FetchAll

This method returns data about all rows of table. Syntax:
$object->fetchAll([$result])
Object
- Object of extension.
Result
- Database result, if it's not mentioned, this method will use result from last call of method select, selectWhere, selectJoin, exists, queryf or query.
Return value: This method returns array with objects with values from row of table, whose number is equal to array key.

Queryf

This method escapes parameters and executes query. Syntax:
$object->queryf(string $prepare, array $array)
Object
- Object of extension.
Prepare
- Query with wildcard characters %0, %1, %2...
Array
- Array with variables, which are going to escape and insert into query instead of wildcard characters.

Select

This method returns and saves code of SELECT command, this command finds saved data in the table. Syntax:
$object->select(string $table[, string $order = NULL[string $orderType = "ASC", [, array $cols = array("*")]]])
Object
- Object of extension.
Table
- Table name.
Order
- Name of column, which will be order argument. If it's NULL, order argument will be time of adding.
OrderType
- ASC or DESC, order direction.
Cols
- List of columns with values, which will fetch(), fetchArray() or fetchAll() method return. If it's array("*"), these methods will return all columns.

SelectWhere

This method returns and saves code of query SELECT, this query finds data saved in the table. Syntax:
$object->selectWhere(string $table, mixed $array[, bool $all = true[, string $order = NULL[, string $orderType = "ASC"[, array $cols = array("*")]]]])
Object
- Object of extension.
Table
- Table name.
Array
- String of SQL condition or array, where key is column name and value is its value. When all respectively one is true, this row is going to be selected.
All
- If it's TRUE, the row will be selected only when all conditions are true, else row will be selected when whichever condition is true.
Order
- Name of column, which will be order argument. If it's NULL, order argumant will be time of adding.
OrderType
- ASC or DESC, order direction.
Cols
- List of columns with values, which will fetch(), fetchArray() or fetchAll() method return. If it's array("*"), these methods will return all columns.

SelectJoin

This method connects two tables and executes query. Syntax:
$object->selectJoin(string $table, string $join, mixed $array[, bool $all = true[, int $joinType = 0[, string $order = NULL[, string $orderType = "ASC"[, array $cols = array("*")]]]]])
Object
- Object of extension.
Table
- Table name.
Join
- Connected table
Array
- String of SQL condition or array, where key is column name and value is its value. When all respectively one is true, this row is going to return.
All
- If it's TRUE, row will be selected only when all conditions are true, else row will be selected when whichever condition is true.
JoinType
- Behavior, when one row won't find match. If it's 0, (INNER), then this row won't be selected. If it's 1(LEFT), then will be selected existing part in first table and missing part will be NULL. If it's 2(RIGHT), then will be selected existing part in connected table and missing part will be NULL. If it's 3(FULL), then existing part will be selected and missing part will be NULL.
Order
- Name of column, which will be order argument. If it's NULL, order argumant will be time of adding.
OrderType
- ASC or DESC, order direction.
Cols
- List of columns with values, which will fetch(), fetchArray() or fetchAll() method return. If it's array("*"), these methods will return all columns.

Exists

This method tests if row is existing. Syntax:
$object->exists(string $table, mixed $array, bool $all)
Object
- Object of extension.
Table
- Table name.
Array
- String of SQL condition or array, where key is column name and value is its value. When all respectively one is true, returns TRUE.
All
- If it's TRUE, this method will return TRUE only when all conditions are true, else this method will return TRUE when whichever condition is true.
Return value: This method returns TRUE or FALSE, if the row is right now existing.

Read

This method reads data from table. Syntax:
$object->read(string $table[, mixed $array[, bool $all = true]])
Object
- Object of extension.
Table
- Table name.
Array
- String of SQL condition or array, where key is column name and value is its value. When all respectively one is true, this row is going to select. If it isn't defined, all rows of this table will be selected.
All
- If it's TRUE, row will be selected only when all conditions are true, else row will be selected when whichever condition is true.
Return value: If the row doesn't exist, this method will return false FALSE, if is existing just one this row, this method returns object from this row like fetch method else, this method returns array with objects from all selected rows (like fetchAll method).

Insert

This method inserts data into table. Syntax:
$object->insert(string $table, array $values[, array $cols = array()[, bool $retId = false]])
Object
- Object of extension.
Table
- Table name.
Values
- Array with values of rows in right order.
Cols
- Array with elements which're going to insert. If it's array() all columns're going to insert.
RetId
- If it's TRUE, this method returns value of column with auto_increment feature.
Return value: If retId is TRUE, this method returns value of column with auto_increment.

Update

This method changes one row of table. Syntax:
$object->update(string $table, array $arr, array $values[, bool $all = true])
Object
- Object of extension.
Table
- Table name.
Arr
- String of SQL condition or array, where key is column name and value is its value. When all respectively one is true, this row se změní.
Values
- Array, where key is column name and value id new value or this column.
All
- Row will be updated only when all conditions are true, else row will be updated when whichever condition is true.

Add

This method adds new column into table. Syntax:
$object->add(string $table, string $name, string $type, int $lenth, bool $null, string $where, string $key[, string $data = NULL])
Object
- Object of extension.
Table
- Table name.
Name
- Name of new column.
Type
- Type of new column, E. G. varchar for text or int alternatively bigint for number.
Null
- Boolean value, if value of column can be empty.
Where
- Before or after, where new column is going to insert.
Key
- Existing column, which new column is going to be before or after it.
Data
- Additional parameters in SQL language about new column.

Change

This method changes a column in table. Synatax:
$object->change(string $table, string $name, string $newName, string $type, int $lenth, bool $null[, string $data = NULL])
Object
- Object of extension.
Table
- Table name.
Name
- Name of column.
NewName
- Column name.
Type
- Type of column, E. G. varchar for text or int alternatively bigint for number.
Null
- Boolean value if value of column can be empty.
Data
- Addition parameners in SQL language about this column.

Drop

This method deletes a column in table. Synatexe:
$object->drop(string $table, string $name)
Object
- Object of extension.
Table
- Table name.
Name
- Name of column, which is going to be deleted.

Delete

This method deletes one row. Syntax:
$object->delete(string $table, mixed $array[, bool $all = true])
Object
- Object of extension.
Table
- Table name.
Array
- String of SQL condition or array, where key is column name and value is its value. When all respectively one is true, this row is going to delete.
All
- If TRUE, row will be deleted only when all conditions are true, else row will be deleted when whichever is true.

Truncate

This method deletes all table rows. Syntax:
$object->truncate(string $table)
Object
- Object of extension.
Table
- Table name