I am trying to build an application that pulls data from a 4D database to fill in form options. Then allow the user to select from those options and submit the form. I am not to familiar with 4D so any advice would be appreciated.
2 Answers
You have multiple options:
PDO. You can use PHP Data Objects (PDO) to connect to 4D via PDO_4D, this uses the 4D SQL protocol. PDO_4D is discussed on the PHP website and on 4D's Knowledge Base.There are a number of forks on Github that include additional bug fixes, see here.
ODBC. If the PHP is running on Windows or Mac and you prefer ODBC over PDO, then you could use the official 4D ODBC Drivers (available for Mac/Win) on the machine running PHP and then use PHP's ODBC commands.
REST. You can write a method in 4D that is accessible via the web and returns a JSON object containing the data you need. Then from your page you can call that REST service to obtain the values. You could use JavaScript to make the call via XHR or you can use PHP to access the REST service.
SOAP. You can write a method in 4D and make the method available via SOAP. Then use a SOAP client in PHP to interact with the soap service.

- 3,551
- 21
- 36
-
Thanks for providing me with multiple options here. I am going to try and use PDO. Do you know if it is possible to use PDO to connect to the database remotely using the IP address rather than localhost? – Tyler Aug 03 '17 at 19:13
-
1Yes using the IP address is fine as long as the network port is open to your PHP client (default port is 19812) – Tim Penner Aug 03 '17 at 19:36
-
Hi Tim, thanks for all your help! I have been talking directly with 4D support trying to figure out if my client with the 4D server needs to do anything else on their end to allow my Apache server to communicate with it, but they have been slow to respond. Do you know of any documentation that explains how to set up their network port to be open to our PHP client? – Tyler Aug 10 '17 at 20:01
-
@Tyler try running a portscan against your 4D server checking specifically if port 19812 is open. You can also just try using telnet to connect to port 19812 to determine if it is open. It is very likely that there is a firewall that is blocking the port thus denying all communication. If so, you will need to allow the port through the firewall. If this is a WAN then you may also need to configure NAT or some other port translation on your router so that the machine is available. Another possibility is that you do not have sufficient licenses to use this feature (i.e. client licenses) – Tim Penner Aug 10 '17 at 20:56
-
Do you know if there is any way to INSERT numbers into the 4D database using PDO. I am able to INSERT strings but numbers throw this error: Invalid SQL data type: 1108 – Tyler Sep 13 '17 at 05:59
Sounds all OK but work. Try to talk with the 4D developer, pushing the informations you need to a MySQL/Maria db is an easy task.
Greetings, Peter

- 167
- 3