Learning
4. The connection of the database:. Crystal4 database connection you can easily connect to the database through PHP, request data and display it on your web site, or even modify data in the database. MySQL is a very popular database and has many tutorials about PHP and MySQL in the Internet. MySQL is free, this may attract a lot of people. Due to its widespread use, I don't want to repeat the use of mysql here. Oracle is used in large quantities in enterprise applications, so we use Oracle to introduce PHP and database connections. We certainly do not mention the design principle of the Oracle database, this has exceeded our discussion. PHP provides two sets of functions and Oracle connections, which are ORA_ and OCI functions, respectively. The ORA_ function is slightly old. OCI function update is more than some. The use of the two use grammar is almost different. As mentioned earlier, your PHP installation option should be able to support both. For more information on installing the Apache server that supports PHP3 on the Microsoft Windows platform and more about Oracle Database, please review the following URL: www.csoft.net/~vsbabu/articles/oraphp.html. 4.1 Connection IF ($ conn = ORA_LOGON ("User @ Tnsname", "Password")) {echo " surcess! Connection to database / n";} else {echo failed: - (COULD NOT CONNECT to Database / N ";} ORA_LOGOFF ($ conn); phpinfo ();?> The above code uses TNSName (indicated in your TNSNAMES.ora file) Oracle database name, user name And password connection database. On the basis of successful connection, the ORA_LOGON function returns a non-zero connection ID and stores in Variable $ Conn. 4.2 Query assumptions are ready to be connected to the database, let's take the actual application to the database.
The following code demonstrates a typical example of a connection and query: / * * Connect the database and perform query * / function printorarr ($ IN_CUR) {// Check whether Oracle error // If there is an error, display // When there is a pointer Each time you request Oracle after requesting Oracle (ORA_ERRORCODE (IN_CUR)) Echo "Oracle Code -". ORA_ERROR ($ IN_CUR). "/ N"; return;} / ** main program * / if (! $ conn = ORA_LOGON ("User @ Tnsname", "Password")))) {Echo "Connection to Database Failed / N"; EXIT;} Echo "Connected As Connection - $ conn b>
/ n "; Echo" Opening Cursor ...
/ n "; $ cursor = ora_open ($ conn); Printorarr ($ Cursor); Echo" Opened Cursor - $ cursor b>
/ N "; $ q =" SELECT User, sysdate from dual "; echo" Parsing the Query $ QRY b> ...
/ n "; ora_parse ($ Cursor, $ Qry, 0); Printorarr ($ Cursor); Echo "Query Parsed
/ N"; Echo "Executing Cursor ...
/ N"; Ora_exec ($ Cursor); Printorarr ($ Cursor); Echo "Executed Cursor
/ N "; echo" fetching cursor ...
/ n "; while (Ora_Fetch ($ Cursor)) {$ User = ORA_GETCOLUMN ($ Cursor, 0); Printoraerr; $ sysdate = ORA_GETCOLUMN ($ Cursor, 1); Printorarr ($ Cursor); Echo "Row = $ user, $ sysdate b>
/ n";} echo "Fetched All Records
/ N"; Echo "Closing Cursor ...
/ N"; ORA_CLOSE ($ CURSOR); Echo "Closed Cursor
/ N"; Echo "Logging Off from Oracle .. .
/ n "; ORA_LOGOFF ($ conn); echo" logged off "?" / N ";?> (Translator Note: The above code segment is missing, please refer to the PHP MANUAL Oracle Database Function section 4.3 Display results The following code demonstrates how to query the database and output the result: <
Function Printorarr ($ IN_CUR, $ conn) {// Check if Oracle error // If there is an error, the display // When the pointer is activated, the function is called after the Oracle is called // if it encountered an error, We exit immediately IF (ORA_ERRORCODE ($ IN_CUR)) {echo "Oracle Code -". ORA_ERROR ($ IN_CUR). "
N"; ORA_LOGOFF ($ conn); exit;} return;} Function EXEQUERY ($ w_qry, $ conn) {$ Cursor = ORA_Open ($ conn); Printorarr ($ Cursor, $ conn); Ora_Parse ($ Cursor, $ W_QRY, 0); Printorarr ($ Cursor, $ conn); Ora_exec ($ CURSOR); Printorarr ($ Cursor, $ conn); $ nuMROWS = 0; $ w_numcols = ORA_NUMCOLS ($ Cursor); // Show head echo "