SQL
extends Base
in package
Class SQL
A class to handle SQL connections and queries
Table of Contents
Properties
- $author : mixed
- $debug_log : mixed
- $debugger : mixed
- $name : mixed
- $url : mixed
- $vars : mixed
- $verbose : mixed
- $version : mixed
Methods
- __construct() : mixed
- connectDB() : mysqli
- connectDB
- connectHost() : mysqli
- connectHost
- countRows() : int
- countRows
- error() : string
- error
- executeQuery() : mixed
- executeQuery
- getUniqueRows() : array<string|int, mixed>
- getUniqueRows
- save_result() : array<string|int, mixed>
- save_result
- search() : mysqli_result
- search
- setupDB() : mixed
Properties
$author
public
mixed
$author
= "Darknetzz"
$debug_log
public
mixed
$debug_log
= []
$debugger
public
mixed
$debugger
$name
public
mixed
$name
= "PHPUtils"
$url
public
mixed
$url
= "https://github.com/Darknetzz"
$vars
public
mixed
$vars
$verbose
public
mixed
$verbose
= \true
$version
public
mixed
$version
= "1.0.0"
Methods
__construct()
public
__construct() : mixed
connectDB()
connectDB
public
connectDB(string $host, string $user, string $pass[, string $db = null ]) : mysqli
Connect to a database
Parameters
- $host : string
-
The host to connect to
- $user : string
-
The username to use
- $pass : string
-
The password to use
- $db : string = null
-
The database to connect to, defaults to null
Return values
mysqli —The mysqli object
connectHost()
connectHost
public
connectHost(string $host, string $user, string $pass) : mysqli
Connect to a host (without a database specified)
Parameters
- $host : string
-
The host to connect to
- $user : string
-
The username to use
- $pass : string
-
The password to use
Return values
mysqli —The mysqli object
countRows()
countRows
public
countRows(string $table[, string $column = null ][, string $value = null ]) : int
Count the number of rows in a table
Parameters
- $table : string
-
The table to count the rows in
- $column : string = null
-
The column to filter by
- $value : string = null
-
The value to filter by
Return values
int —The number of rows in the table
error()
error
public
error() : string
Get the last error from the SQL connection
Return values
string —The last error from the SQL connection
executeQuery()
executeQuery
public
executeQuery(string $statement[, array<string|int, mixed> $params = [] ][, string $return = "result" ]) : mixed
Execute a query
Parameters
- $statement : string
-
The SQL statement to execute
- $params : array<string|int, mixed> = []
-
The parameters to bind to the statement
- $return : string = "result"
-
The type of return to expect (id, array, object)
getUniqueRows()
getUniqueRows
public
getUniqueRows(string $table, string $column) : array<string|int, mixed>
Get the unique rows from a table
Parameters
- $table : string
-
The table to get the rows from
- $column : string
-
The column that should be unique
Return values
array<string|int, mixed> —The unique rows
save_result()
save_result
public
save_result(mysqli_result $query) : array<string|int, mixed>
Save the result of a query to an array
Parameters
- $query : mysqli_result
-
The query to save
Return values
array<string|int, mixed> —The result of the query
search()
search
public
search(string $tablename, string $search[, array<string|int, mixed> $columns = ["name"] ][, array<string|int, mixed> $options = [] ]) : mysqli_result
Search a table for a string
Parameters
- $tablename : string
-
The table to search
- $search : string
-
The string to search for
- $columns : array<string|int, mixed> = ["name"]
-
The columns to search in
- $options : array<string|int, mixed> = []
-
The options for the search
- delimiter: The string to split the search string by
- limit: The maximum number of results to return (default 0 = no limit)
- casesensitive: Whether the search should be case sensitive (default False)
- strip_chars: Whether to strip special characters from the search string (default True)
- search_min_len: The minimum length of the search string (default 0 - no minimum length)
Return values
mysqli_result —The result of the search
setupDB()
public
setupDB(mixed $sqlcon, mixed $templateArray) : mixed
Parameters
- $sqlcon : mixed
- $templateArray : mixed