Search code examples
phporacle-databasexcodeosx-snow-leopardvmware

connect mac os x php to oracle XE on vmware


I'm coding a mac app in XCode which switches between mySQL and Oracle databases. I have successfully managed to communicate with my mySQL database via PHP, but I'm at a loss on how to connect to my Oracle database (11g XE) running under WinXP in VMWare on my mac. I checked phpinfo and do have odbc installed with my version of PHP and I have my VMWare networking set to NAT. I'm kinda new to this. Any advice?

I've tried this script:

<?php

$conn = odbc_connect('username', 'password', 'myHost/XE');

if (!$conn) {
trigger_error("Could not connect to database", E_USER_ERROR);
}


?>

Solution

  • Here's my tnsnames entry for my private oracle instance which I've named MHORCL. Oracle is running on an ubuntu vmware client on my mac vmware host.

    You can edit (or create) /etc/tnsnames.ora, adding a similar entry. Your connection string will be somethig like scott/tiger@mhorcl.

    #-------------------------------------------------------------------------------
    # mhorcl -- mark's scratch server. it's behind a private vmware
    #-------------------------------------------------------------------------------
    
    MHORCL =                ##### WHATEVER LOGICAL NAME YOU WANT
      (DESCRIPTION=
        (ADDRESS=
          (PROTOCOL=TCP)
          (HOST=168.3.1.3)  #### WHATEVER YOUR WINDOWS IP ADDRESS IS
          (PORT=1521)
        )
        (CONNECT_DATA=
          (SERVER=dedicated)
          (SERVICE_NAME=xe)
        )
      )