Database Class
Abstract database connection. Use's the mysqli API.
$db = new Database('localhost', 'root', '12341234', 'my_database');
Constructor
Item Index
Methods
- cacheAll
- cacheNext
- create
- currentAlias
- currentDatabase
- delete
- disconnect
- drop
- escapeString
- execute
- flush
- getArray
- getDatabaseName
- getLength
- getResult
- getRow
- insert
- insertId
- internalExecute
- isConnected
- nextId
- parseQueries
- parseResults
- read
- save
- select
- setCache
- setDatabase
- show
- startPooling
- stopPooling
- tableExists
- truncate
- update
Methods
cacheAll
-
[enabled=true]
If we want to turn on caching for all select, row, result or count
Parameters:
-
[enabled=true]
Boolean optionalIf we should enable this defaults to true
cacheNext
()
Cache the next select, row, result or count
create
-
table
Create a new table on the database
Parameters:
-
table
StringThe name of the table to create
Returns:
The create query
currentAlias
()
String
Get the currently selected database alias
Returns:
Name database alias
currentDatabase
()
String
Get the currently selected database
Returns:
Name of the actual database name (not the alias)
delete
-
tables
A method for deleting rows from table(s)
Parameters:
-
tables
String multipleThe tables as arguments e.g. delete('users', 'users_other')
Returns:
New delete query
disconnect
()
Close the database connection, if any is open
drop
-
table
Remove a table
Parameters:
-
table
StringThe name of an existing table to drop
Returns:
The new drop query
execute
-
sql
Execute a query
Returns:
The mysqli query object
getArray
-
sql
-
[cache=false]
Fetch an array of associate array results for a query
Parameters:
Returns:
The array of results or null (if invalid result)
getDatabaseName
-
[alias='default']
Get the name of the database by an alias
Parameters:
-
[alias='default']
String optionalThe valid database alias to check by
Returns:
The name of the database
getLength
-
sql
-
[cache=false]
Count the number of return rows for a sql query
Returns:
Number of rows
getResult
-
sql
-
field
-
[position=0]
-
[cache=false]
Fetch a single value from an sql call
Parameters:
Returns:
The value of the field or null
getRow
-
sql
-
[cache=false]
Fetch a single row from the database
Returns:
The row as a non-associative array
insert
-
tables
Insert query
Parameters:
-
tables
String multipleThe tables as arguments e.g. insert('users', 'users_other')
Returns:
New insert query
insertId
()
Int
Returns the auto generated id used in the last query
Returns:
The integer for the last insert
internalExecute
-
sql
Execute a query internally
Returns:
The mysqli query object
isConnected
()
Boolean
Check to see if the database is currently connected
Returns:
If the database is connected
nextId
-
table
-
field
Function to get the next ordered ID from a table index
Returns:
The integer for the next ID
parseQueries
-
sql
-
type
-
[cache=false]
-
[field=null]
-
[position=null]
Parse the queries as a type
Parameters:
-
sql
String | Query | ArrayThe collection or single SQL query
-
type
StringThe type of parse, 'getRow', 'getResult', 'getArray', 'getLength'
-
[cache=false]
Boolean optionalIf we should cache the result
-
[field=null]
String optionalThe field name for getResult
-
[position=null]
Int optionalThe position number for getResult
Returns:
The result data
parseResults
-
results
-
type
-
[field=null]
-
[position=null]
Parse the queries as a type
Parameters:
Returns:
The result data
read
-
type
-
sql
-
cache
Get the cache data if available and active
Parameters:
Returns:
The cached data or false
save
-
type
-
sql
-
data
-
cache
Save the cache data
Parameters:
Returns:
If the cache was saved
select
-
[properties='*']
Create a select query
Parameters:
Returns:
The select query
setCache
-
cache
Set a cache object to use
Parameters:
-
cache
IDatabaseCacheThe cache object, interface with IDatabaseCache
setDatabase
-
[alias='default']
Change the database by an alias
Parameters:
-
[alias='default']
String optionalThe alias to change to
Returns:
Return 1 if we have changed and error's if we haven't
show
-
[alias='']
Show the current tables on a database
Parameters:
-
[alias='']
String optionalThe optional alias, defaults to the current database
Returns:
The array of tables on this database
startPooling
()
Turn on query pooling, this will not execute queries until stopPooling is called
stopPooling
-
[cache=false]
Execute the pooled queries in the order in which they were added
Parameters:
-
[cache=false]
Boolean optionalIf se should cache the result for later
Returns:
The result objects or null if no pooling
tableExists
-
table
-
[alias='']
Check to see if a table exists
Parameters:
Returns:
If the table exists or not
truncate
-
table
Remove all of the rows from a table
Parameters:
-
table
StringThe name of the table to truncate
Returns:
The new truncate query
update
-
tables
An update function
Parameters:
-
tables
String multipleThe tables as arguments e.g. update('users', 'users_other')
Returns:
New update query
Properties
_connection
Mysqli
private
The mysql connect