Skip to content

Connecting to a Database

teodorpk edited this page Jun 5, 2018 · 6 revisions

It is really easy to connect to your database, using Wappler. The first thing you need to do is to open the Server Connect panel:

If you have not selected your server model when defining your project, then you will see a message saying that you need to specify one. Click the project options button:

Open the server model drop-down and select one - PHP, ASP.NET or Classic ASP:

In order to connect to a database, we also need to setup a target. You can do this by clicking the Targets menu (1) and then the Add new target button (2):

Enter the target name and URL:

Then select the Target Type. This can be a local folder on your computer, where you are running some server (WAMP, MAMP or IIS) or a remote server which you connect to using the required FTP details:

If you select FTP, then you need to enter the address, port, username, password and the remote directory (if this is required). You can test the FTP connection by clicking the Test Connection button:

In our case, we are using a local folder and a WAMP server, so we just selected Local Folder and setup the paths:

When you select a server model server connect shows you the toolbar and panels. The first thing you need to do, is to create a Server Action. Server Actions store your workflows, and execute the steps you visually set up. The toolbar allows you to create a server action, create a folder or delete a server action/folder. For a better structuring especially on large sites, using many server actions we recommend to group your server actions in folders. We create a new folder:

We call it "data". Inside it we create a new server action:

We add a name for it: "records"

When you create the server action you will see the action steps panel, with its options. Right click steps in order to add a new step:

We open the database actions menu:

Then we Add Database Connection:

Before clicking the database connection options, we need to make sure we selected the right target. This is the target we've already setup earlier:

Click the Connection Options button:

The Database Connection options window appears. Select your database type:

Then the database options will be displayed. Enter the sever address, port, username, password and database name:

You can test the connection by clicking the Test Connection button. If everything is OK you will see the Connection OK notification:

Click the Save button, in order to apply the connection settings:

You can see your connection in the server action. The blue link button after the connection name means that this connection is linked to your current site and you can reuse it in all of your action files by just loading it using the folder button:

Click the Save button in order to save your server action:

You will see a notification saying that the server action has been successfully saved:

NEXT: Learn how to setup a database query using this database connection

Clone this wiki locally