Multiple targets and separate server connections

Wappler Version : 2.7.2
Operating System : Windows 10 pro

Expected behavior

One would want to see different database host, user and credentials recorded for different targets.

Actual behavior

The same connection credentials are applied to all targets, and changing one is applied to all (ie it seems the same connection file is generated instead of having one per target).

How to reproduce

  1. Create several targets
  2. Create a connection in your project
  3. Open the connection and choose a different target. Makes changes accordingly.
  4. Revert to previous target, the changes have been applied as well.



Hi, I think I had the same problem and struggled with it for some time before I found a work around.
This worked on both macos and windows:

First, just have one database connection for each target. This gets cluttered when you suddenly change the connection name and save the connection. The previous connection file isn’t removed.

Second, go to each folder “projectname”/.wappler/targets/“targetname”/files/dmxConnect/modules/Connections" and name the connection file the same for each target. (You can also edit the file manually while your at it.)

Be sure to remove old or unused connection files so you just have one single connection file per target.

Example:
“.wappler/targets/localhost_instance1/files/dmxConnect/modules/Connections/dbconnection.php”
“.wappler/targets/BlueHost/files/dmxConnect/modules/Connections/dbconnection.php”
“.wappler/targets/Home Server/files/dmxConnect/modules/Connections/dbconnection.php”

The “.wappler”-folder may be hidden so you will have to make sure you can see hidden files/folders in Finder/Explorer.

Hope this helps you keep from ripping your hair off.

Hi @avolo,

Thanks for the insight - I only had one connection file to start with, so this case might be a little different from your own. I did check the 3 different locations and I can see that they all share the same credentials, which they shouldn’t - this may further show something is off here.

I’ll try manually editing them and see if the information sticks.

Hi Nathaniel, I should make clear that the key in my case was renaming all the db connection files so they all had the same filename.
I hope you find a solution to your problem and report it back. I suspect others are having similar problems and all work arounds are welcome until a fix is presented.
Good luck! :slight_smile:

(edit: I used “db.php” as connection filename in all targets. Should not matter, but maybe worth mentioning.)

So, opening each target’s connection file and editing the credentials and then opening wappler and changing targets on the bottom bar selector to get them published, seems to work. I don’t know if they will be later overwritten by further editing projects, though.

Thanks for the pointer @avolo, with a little luck this may be enough until it’s fixed on the product side.

You’re most welcome and glad you got it working. I’m still wondering though if the filename for the dbconnection is of any importance?
I used “db.php” because I read in the feature description that “Whappler automatically creates a db.php file per target” or something like that.
So what did you name your connection files?

Actually this is not a bug but something to know:

  • Connections get saved only when you close the dialog or hit the save button next to the target

So if you just switch targets, previous connection info will get lost.

So make sure you hit the save before switching if you don’t close the dialog in the mean time.

We could improve that by giving an alert for unsaved changes, when just switching.

Thanks for the clarification George.
I remember when I first tried this feature out that upon switching targets in the toolbar, the database connection name didn’t switch in the GUI for the server action file I had in view like I expected it to do.
That’s why I tried to name all dbconnection files the same and that solved my problem.

Yes, changes seem to be saved now, when I press the save button (which I thought I had done previously). Maybe what threw me off is that when you create targets, the credentials from your existing connection are duplicated, and what I was expecting was for them to be blank.

Thanks for the clarification, @George.

Actually, I do find a behavior that could be a bug, @George:

  • I am able to see 3 different credentials for my 3 different targets, but:

  • the credential of the active target are applied to the other targets: if I’m working against an ftp, my local target connection uses the credentials of the target with the ftp, instead of using the credentials assigned to the local connection.

On active target switch the connection from that target should be copied as local and used.

Isn’t that the case with you?

Hi George,

No, that’s not the behavior I get. What I’m seeing is that the connection of the active target is used by all the targets. Right now my active target is my ftp and my local server is giving an error and showing my active, remote target credentials instead of the credentials of its own, local, connection file:

Hi @George, here is some additional data after upgrading to wappler 2.8.2.
If I switch from my ftp target to my local target, I get this prompt when trying to create a query:


I see no options to active a connection/target.
If I click on “check” at the right on my “target: local”, what you see processed on the console is actually my remote ftp, not my local setup.

Okay, I think I have found a valid workaround.
In order to have the correct connection applied to a particular target, one needs to:

  1. Switch targets
  2. Open any db connection from a server side action
  3. Click on save, without doing any changes

Then the target updates the remote server with the appropriate connection, otherwise it carries over whatever your first target connection credentials were.

@Nathaniel
You can’t test a connection or create a database query if you have not selected a target with a webserver defined. How is this “local” target which you selectedselected on your screenshot defined exactly?

Are you referring to the project settings, @Teodor? In the first pane (general) I have the server model (php) and in the third pane, I defined each of my targets:

On your previous screenshot there is NO target selected!
It’s set to LOCAL and that is the reason you see the error message there.

Yes, you’re right. The upload of the correct connection file to the right target persist though, unless it is manipulated first from an action file .

Sorry, i don’t understand what you mean.
All you need to do is to create ONE connection in server connect.
Then in this connection you define the connection details per each of the available targets and click the save buton to save them.

When you change your targets, the connection details will change accordingly.
I’m not sure i understand what exactly are you doing there :slight_smile:

Yes I’m finding this to be true as well.

When I switch between my local docker dev target and my remote web server target, I have to follow your steps 1 to 3 to populate server connection info on that target.

I’m on a Mac.