Php connection to oracle Database code
Php connection to oracle Database code
Php connection to oracle Database code
Connect to oracle code
$ Conn = OCILogon ("scott", "tiger", "your oracle Database Name ");
$ Stmt = OCIParse ($ conn, "select empno, ename from emp ");
/* Use OCIDefineByName before executing OCIExecute */
OCIDefineByName ($ stmt, "EMPNO", & $ empno );
OCIDefineByName ($ stmt, "ENAME", & $ ename );
OCIExecute ($ stmt );
While (OCIFetch ($ stmt )){
Echo "empno:". $ empno. "n ";
Echo "ename:". $ ename. "n ";
}
OCIFreeStatement ($ stmt );
OCILogoff ($ conn );
/*
Note:
By default, php cannot be connected to the oracle database. We have to modify it in the Windows Extensions section of php. ini
Extension_dir = "file path of the dll to be loaded" (for example, c: phpextensions)
Extension = php_oci8.dll
Extension = php_oracle.dll
Step 2:
Set isapi in iis
*/
// Php connection to the oracle database Code 2
If ($ conn = Ora_Logon (""))
{
Echo "SUCCESS! Connected to databasen ";
}
Else
{
Echo "Failed:-(cocould not connect to databasen ";
}
Ora_Logoff ($ conn );
// Connect to database instance 3
$ Connection = Ora_Logon ("", "123 ");
If ($ connection = false ){
Echo Ora_ErrorCode ($ connection). ":". Ora_Error ($ connection )."";
Exit;
}
$ Cursor = Ora_Open ($ connection );
If ($ cursor = false ){
Echo Ora_ErrorCode ($ connection). ":". Ora_Error ($ connection )."";
Exit;
}
Ora_Commit ($ connection );
Ora_Close ($ cursor );
Ora_Logoff ($ connection );
/*
Function Description:
Integer ora_logon (string user, string password) connects to the oracle database server based on the specified user
Query the connection provided by integer ora_open (integer connection. PHP generates an indicator to parse the query
Integer ora_do (integer connection, string query) is queried and ready for execution
Query parsed by the integer ora_parse (integer cursor, string query) ora_parse function.