WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\database

class Database

Class Methods Summary

public function __construct(ConnectionInfo$connectionInfo)Creates new instance of the class.public function addQuery(string$query, string$type)Adds a database query to the set of queries at which they where executed.public function addTable(Table$table)Adds a table to the instance.public function andWhere(AbstractQuery|string$col, string$cond, mixed$val)Build a 'where' expression.public function clear()Rest all attributes of the class to original values.public function createTable()Constructs a query which can be used to create selected database table.public function createTables()Create SQL query which can be used to create all database tables.public function delete()Constructs a query which can be used to remove a record from the selected table.public function drop()Constructs a query which will drop a database table when executed.public function execute()Execute SQL query.public function getConnection()Returns the connection at which the instance will use to run SQL queries.public function getConnectionInfo()Returns an object that holds connection information.public function getLastError()Returns the last database error info.public function getLastQuery()Returns the last generated SQL query.public function getLastResultSet()Returns the last result set which was generated from executing a query such as a 'select' query.public function getName()Returns the name of the database.public function getQueries()Returns an indexed array that contains all generated SQL queries.public function getQueryGenerator()Returns the query builder which is used to build SQL queries.public function getTable(string$tblName)Returns a table structure as an object given its name.public function getTables()Returns an array that contains all added tables.public function hasTable(string$tableName)Checks if a table exist in the database or not.public function insert(array$colsAndVals)Constructs a query which can be used to insert a record in the selected table.public function limit(int$limit)Sets the number of records that will be fetched by the query.public function offset(int$offset)Sets the offset.public function orWhere(AbstractQuery|string$col, string$cond, mixed$val)Build a 'where' expression.public function page(int$num, int$itemsCount)Constructs a query which can be used to fetch a set of records as a page.public function select(array$cols)Constructs a query that can be used to get records from a table.public function setConnection(Connection$con)Sets the connection that will be used by the schema.public function setConnectionInfo(ConnectionInfo$info)Sets database connection information.public function setQuery(string$query)Sets the database query to a raw SQL query.public function table(string$tblName)Select one of the tables which exist on the schema and use it to build SQL queries.public function truncate()Constructs a query which will truncate a database table when executed.public function update(array$newColsVals)Constructs a query which can be used to update a record in the selected table.public function where(AbstractQuery|string$col, string$cond, mixed$val, string$joinCond)Build a where condition.

Class Methods Details

public function __construct(ConnectionInfo$connectionInfo)Creates new instance of the class.

Parameters:

  • ConnectionInfo $connectionInfo An object that holds database connection information.
public function addQuery(string$query, string$type)Adds a database query to the set of queries at which they where executed. This method is called internally by the library to add the query. The developer does not have to call this method manually.

Parameters:

  • string $query SQL query as string.
  • string $type The type of the query such as 'select', 'update' or 'delete'.
public function addTable(Table$table)Adds a table to the instance.

Parameters:

  • Table $table the table that will be added.
Returns: booleanIf the table is added, the method will return true. False otherwise.
public function andWhere(AbstractQuery|string$col, string$cond, mixed$val)Build a 'where' expression. This method can be used to append an 'and' condition to an already existing 'where' condition.

Parameters:

  • AbstractQuery|string $col A string that represents the name of the column that will be evaluated. This also can be an object of type 'AbstractQuery' in case the developer would like to build a sub-where condition.
  • string $cond A string that represents the condition at which column value will be evaluated against. Can be ignored if first parameter is of type 'AbstractQuery'.
  • mixed $val The value (or values) at which the column will be evaluated against. Can be ignored if first parameter is of type 'AbstractQuery'.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function clear()Rest all attributes of the class to original values. public function createTable()Constructs a query which can be used to create selected database table. Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.public function createTables()Create SQL query which can be used to create all database tables. Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.public function delete()Constructs a query which can be used to remove a record from the selected table. Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.public function drop()Constructs a query which will drop a database table when executed. Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.public function execute()Execute SQL query. Returns: ResultSet|nullIf the last executed query was a select, show or describe query, the method will return an object of type 'ResultSet' that holds fetched records. Other than that, the method will return null.public function getConnection()Returns the connection at which the instance will use to run SQL queries. This method will try to connect to the database if no connection is active. If the connection was not established, the method will throw an exception. If the connection is already active, the method will return it.Returns: ConnectionThe connection at which the instance will use to run SQL queries.public function getConnectionInfo()Returns an object that holds connection information. Returns: ConnectionInfoAn object that holds connection information.public function getLastError()Returns the last database error info. Returns: arrayThe method will return an associative array with two indices. The first one is 'message' which contains error message and the second one is 'code' which contains error code.public function getLastQuery()Returns the last generated SQL query. Returns: stringLast generated SQL query as string.public function getLastResultSet()Returns the last result set which was generated from executing a query such as a 'select' query. Returns: ResultSet|nullThe last result set. If no result set is available, the method will return null.public function getName()Returns the name of the database. Returns: stringThe name of the database.public function getQueries()Returns an indexed array that contains all generated SQL queries. Returns: arrayAn indexed array that contains all generated SQL queries.public function getQueryGenerator()Returns the query builder which is used to build SQL queries. Returns: AbstractQuery public function getTable(string$tblName)Returns a table structure as an object given its name.

Parameters:

  • string $tblName The name of the table.
Returns: Tablethe table.
public function getTables()Returns an array that contains all added tables. Returns: arrayThe method will return an associative array. The indices of the array are tables names and the values are objects of type 'Table'.public function hasTable(string$tableName)Checks if a table exist in the database or not.

Parameters:

  • string $tableName The name of the table.
Returns: booleanIf the table exist, the method will return true. False if it does not exist.
public function insert(array$colsAndVals)Constructs a query which can be used to insert a record in the selected table.

Parameters:

  • array $colsAndVals An associative array that holds the columns and values. The indices of the array should be column keys and the values of the indices are the new values.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function limit(int$limit)Sets the number of records that will be fetched by the query.

Parameters:

  • int $limit A number which is greater than 0.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function offset(int$offset)Sets the offset. The offset is basically the number of records that will be skipped from the start.

Parameters:

  • int $offset Number of records to skip.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function orWhere(AbstractQuery|string$col, string$cond, mixed$val)Build a 'where' expression. This method can be used to append an 'or' condition to an already existing 'where' condition.

Parameters:

  • AbstractQuery|string $col A string that represents the name of the column that will be evaluated. This also can be an object of type 'AbstractQuery' in case the developer would like to build a sub-where condition.
  • string $cond A string that represents the condition at which column value will be evaluated against. Can be ignored if first parameter is of type 'AbstractQuery'.
  • mixed $val The value (or values) at which the column will be evaluated against. Can be ignored if first parameter is of type 'AbstractQuery'.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function page(int$num, int$itemsCount)Constructs a query which can be used to fetch a set of records as a page.

Parameters:

  • int $num Page number. It should be a number greater than or equals to 1.
  • int $itemsCount Number of records per page. Must be a number greater than or equals to 1.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function select(array$cols)Constructs a query that can be used to get records from a table.

Parameters:

  • array $cols An array that holds the keys of the columns that will be selected.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function setConnection(Connection$con)Sets the connection that will be used by the schema.

Parameters:

public function setConnectionInfo(ConnectionInfo$info)Sets database connection information.

Parameters:

public function setQuery(string$query)Sets the database query to a raw SQL query.

Parameters:

  • string $query A string that represents the query.
Returns: DatabaseThe method will return the same instance at which the method is called on.
public function table(string$tblName)Select one of the tables which exist on the schema and use it to build SQL queries.

Parameters:

  • string $tblName The name of the table.
Returns: AbstractQuery|MySQLQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function truncate()Constructs a query which will truncate a database table when executed. Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.public function update(array$newColsVals)Constructs a query which can be used to update a record in the selected table.

Parameters:

  • array $newColsVals An associative array that holds the columns and values. The indices of the array should be column keys and the values of the indices are the new values.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
public function where(AbstractQuery|string$col, string$cond, mixed$val, string$joinCond)Build a where condition.

Parameters:

  • AbstractQuery|string $col A string that represents the name of the column that will be evaluated. This also can be an object of type 'AbstractQuery' in case the developer would like to build a sub-where condition.
  • string $cond A string that represents the condition at which column value will be evaluated against. Can be ignored if first parameter is of type 'AbstractQuery'.
  • mixed $val The value (or values) at which the column will be evaluated against. Can be ignored if first parameter is of type 'AbstractQuery'.
  • string $joinCond An optional string which can be used to join multiple where conditions. If not provided, 'and' will be used by default.
Returns: AbstractQueryThe method will return an instance of the class 'AbstractQuery' which can be used to build SQL queries.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024