Sunday, May 6, 2012

Xampp with PHP and Oracle from Mysql

Oracle Based Changes

1. Install oracle any version
2. configure with database creation ( database will create automatically )
3. import mysql tables to oracle
4. Note hostname, username, password and SID.
5. While start the xampp if NLS_LANG error will come for oci8 follow the below steps
a.) run --> regedit --> hkey local machine --> softwares --> oracle --> NLS_LANG key rename or delete

b.) restart system.


PHP Based Changes After Installed Xampp

1. In your XAMPP Start Page, go to phpinfo, look for string oci8. If string found it indicate that connection to oracle is available, otherwise to activate connection do the following steps:
2. Open the currently used php.ini file by looking at the phpinfo, from the XAMPP folder.
3. Find string ;extension=php_oci8.dll. Remove the semicolon (;) ahead of the string to activate the oracle extension.
4. Save the php.ini file.
5. Download the “Instant Client Package – Basic” for Windows from the OTN Instant Client page. Unzip it to c:\instantclient_11_1
6. Edit the PATH environment setting and add c:\instantclient_11_1 before any other Oracle directories. For example, on Windows XP, follow Start -> Control Panel -> System -> Advanced -> Environment Variables and edit PATH in the System variables list.
7. Set desired Oracle globalization language environment variables such as NLS_LANG. If nothing is set, a default local environment will be assumed. See An Overview on Globalizing Oracle PHP Applications for more details.
8. Unset Oracle variables such as ORACLE_HOME and ORACLE_SID, which are unnecessary with Instant Client (if they are set previously).
9. Restart XAMPP (or Start if its not already started).
10. To make sure that connection to oracle database has successfully activated, go to phpinfo. Find string: oci8. If found, then XAMPP can now communicate with Oracle Database.

PHP Based sample connection

$conn = oci_connect('username', 'password', 'host:port/servicename');
$query = 'select table_name from user_tables';
$stid = oci_parse($conn, $query);
oci_execute($stid, OCI_DEFAULT);
while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
foreach ($row as $item) {
echo $item." | ";
}
echo "
\n";
}
oci_free_statement($stid);
oci_close($conn);



ADODB Based Sample Connection



$DB = NewADOConnection("oci8");
$DB->Connect('localhost', 'system', 'system', 'orasrv');



No comments:

Post a Comment