Server Database Connections
HTML5 Builder server-side applications, both web and mobile, can interact with database servers to retrieve, modify, add and remove data.
There are several approaches you can follow:
- Component-based approach, or the RAD way.
- Components and code. You can establish a connection to a database using components, and then interact with DataSet components from code to manipulate the data.
- Code. You can use pure PHP for database connections. Check the PHP manual for your DBMS.
- Custom Data-aware Controls. You can create your own controls that can interact with databases. See how to create a component, and make it data-aware.
Contents
Components
You can combine data-access components and data controls to develop web applications that read or write on databases, and can perform advanced operations with them. Follow the steps below to configure a connection:
Note: You can use the Data Explorer instead to speed up the whole process.
Connect to a Database
To work with a database, you first need to get a working connection to one. In HTML5 Builder, the component that takes care of that connection is Database. You can either add a Database component to your application from the Tool Palette and then configure it, or you can drop a database onto the Designer directly from the Data Explorer, which will generate a Database component already configured.
Configure a DataSet
Once the connection is ready, you need to retrieve some data from it. There are several components you can use to retrieve data from a Database, those called DataSet components, components that extend the DataSet class.
DataSet components perform a query on the Database component and store the resulting data.
Associate a Component to the DataSet
There are some components that can be associated with a DataSet component so the former renders the data in the second. Those components are called data-aware components. But in order to make that association, you need a connector, a bridge between the DataSet component and the data-aware component: a Datasource component. That is why all data-aware components have a DataSource property you have to point to that DataSource component.
So once you have a working DataSet component, you need to:
- Add a Datasource component to your application, and set it up to work with the DataSet component.
- Add a data-aware component and set its DataSource property to the Name property of the DataSource component.
That is it. Your component will now work with the data from the database.
Using a Data Module
You can place any Database, DataSet and Datasource components in a server data module. That way, you can later include that module from any other page, avoiding duplicated work by reusing the same components.
Components and Code
After you follow the component-based approach to configure a Database component and link one or more DataSet components to it, you can directly access the data from the latter using code.
For information on how to interact with these components from code, see DataSet Components.
Tools
The following tools will help you work with databases:
- Data Explorer
- It lets you browse your databases, generate components already set up to work with them, and more.
- Query Designer
- Design queries to be executed against your databases in a visual way.
- Data Viewer
- Read, edit and create data from your databases.
Help Resources
Tutorials
Video Tutorials
- HTML5 Builder Mobile Development & Deployment.
- 10:50 — Writting a server mobile page connected to an InterBase database.
See Also
- Supported DBMS.
- DBMS-specific Documentation: DB2, Firebird, Informix, InterBase, Microsoft SQL Server, MySQL, NexusDB, Oracle, PostgreSQL, SQLite.
- Alternatives: Client-side Storage, MDB.