Configuring Zend Server
I got all the screen shots out last night, then I realized that the configuration instructions were missing. They’ve been added now, and you can check if you’re interested.
In the process, I noticed that Zend Server Community Edition is using connection pooling by default with Oracle. This means that the TNS alias must be qualified by a hostname
.
For example, on your local PC with Oracle Database 10g Express Edition, the default TNS alias is XE
. You can’t use that anymore when you’re running the Zend Server. You must qualify it as localhost/XE
or hostname/XE
as the connection string. A natural alternative is to insert a fully qualified TNS network map
Here are three possible connection patterns:
Localhost Connection ↓
This shows you how to connect with localhost/XE
.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php // Attempt to connect to your database. $c = @oci_connect("student", "student", "localhost/xe"); if (!$c) { print "Sorry! The connection to the database failed. Please try again later."; die(); } else { print "Congrats! You've connected to an Oracle database!"; oci_close($c); } ?> |
If you connect with a localhost
string, your listener logs will show the following:
02-JUL-2009 23:32:11 * (CONNECT_DATA=(SERVICE_NAME=xe)(CID=(PROGRAM=C:\Program?Files\Zend\ZendServer\bin\php-cgi.exe)(HOST=MCLAUGHLINXP32)(USER=SYSTEM))) * (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1405)) * establish * xe * 0 |
The two things to point out with this are: (1) The host
is 127.0.0.1
; and (2) The TNS alias is lowercase.
Hostname Connection ↓
This shows you how to connect with hostname/XE
.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php // Attempt to connect to your database. $c = @oci_connect("student", "student", "hostname/xe"); if (!$c) { print "Sorry! The connection to the database failed. Please try again later."; die(); } else { print "Congrats! You've connected to an Oracle database!"; oci_close($c); } ?> |
If you connect with a hostname
string, your listener logs will show the following:
02-JUL-2009 23:29:16 * (CONNECT_DATA=(SERVICE_NAME=xe)(CID=(PROGRAM=C:\Program?Files\Zend\ZendServer\bin\php-cgi.exe)(HOST=MCLAUGHLINXP32)(USER=SYSTEM))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.16.153.138)(PORT=1403)) * establish * xe * 0 |
The two things to point out with this are: (1) the host
is the real IP address on the network; and (2) the TNS alias is lowercase.
Overriding TNS Connection ↓
This shows you how to connect with an overriding TNS connection.
Before you adopt this style, you may want to set a %TNS_ADMIN%
for your Windows OS. The suggestion is made since you may be running the client software and there’s a connection problem. You can click on the Setup a TNS_ADMIN Environment Variable menu to get at the details.
Set a TNS_ADMIN Environment Variable ↓
You can also set a %TNS_ADMIN%
environment variable, by taking the following steps.
- Open your System icon from the traditional Control Panel. Inside, click on the Advanced tab. Click the Environment Variable tab.
- The bottom window is where you set System variables. Click the New button to add a %TNS_ADMIN% variable.
- The New System Variable Window lets you enter the variable. Unless you’ve placed your
tnsnames.ora
in a different location, you find the file in the ORACLE_HOME\network\admin. If you’ve installed Oracle XE and Oracle on the same machine, you should know which contains both values because you entered them. The utilities don’t do that. If somebody has a question on that, let me know and I’ll put instructions out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php $tns = "(DESCRIPTION = (ADDRESS=(PROTOCOL = TCP)(HOST = mclaughlinxp32)(PORT = 1521)) (CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = XE)))"; // Attempt to connect to your database. $c = @oci_connect("student", "student", $tns); if (!$c) { print "Sorry! The connection to the database failed. Please try again later."; die(); } else { print "Congrats! You've connected to an Oracle database!"; oci_close($c); } ?> |
If you connect with an overriding TNS connection, your listener logs will show the following:
02-JUL-2009 23:27:10 * (CONNECT_DATA=(SERVICE_NAME=XE)(CID=(PROGRAM=C:\Program?Files\Zend\ZendServer\bin\php-cgi.exe)(HOST=MCLAUGHLINXP32)(USER=SYSTEM))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.16.153.138)(PORT=1401)) * establish * XE * 0 |
The two things to point out with this are: (1) the host
is the real network IP address; and (2) the TNS alias is uppercase, which is consistent with the TNS connection string.
I’m sure it was in the documents but then again, I didn’t read them. 😉