How to Connect 4D With PHP
4D is a programming and delivery platform for Web-based applications. It includes all the components necessary to provide a comprehensive website environment. This includes a database application, the Web server itself, a separate server to host applications, a graphical Web design platform and more. The system can integrate with the PHP programming language through PHP's own "PDO_4D" driver interface. This tool is specifically designed to connect the 4D environment to the the PHP compiler for added flexibility. The PDO protocol is easily called inside any PHP program and is primarily used to interact with the 4D database server instead of other databases usually combined with PHP.
Instructions
-
-
1
Identify the key login details for the 4D server. These are required in the PHP program script to connect the two platforms. You must know these in advance of creating the PHP code. The most important information consists of the username and password of the 4D database and the host name of the server.
-
2
Open a PHP program for editing. This may be an existing PHP script or a new program.
-
-
3
Create a text string that comprises the primary login information for the 4D server. The string must be formatted strictly, using the PDO syntax. Declare the string variable, then type "4D:host=localhost" where "localhost" is the name of the host server. For example, the final PHP line may look like: "$dsn = '4D:host=localhost';" where "$dsn" is the name of the variable you choose to use. Note that double quotes are not included in the actual program code.
-
4
Create another variable definition for the username. For example, "$username='username';". Do the same for the password.
-
5
Connect to the 4D database server using the defined variables within the "PDO" PHP function. The program line may appear as: "$db = new PDO($dsn, $username, $password);".
-
6
Run the PHP program. If no errors are presented, the code is successful and you have correctly connected PHP with 4D.
-
1
References
- Photo Credit www and internet image by mbs from Fotolia.com