6. ANÁLISIS, INTERPRETACIÓN Y DISCUSIÓN DE LOS RESULTADOS
6.1 DESCRIPCIÓN DE LAS CONCEPCIONES DE LA ORALIDAD Y DE LAS
6.1.2 Concepciones Docentes y de Estudiantes Sobre Actividades Orales en el Aula de
6.1.2.2 Concepción “Actividades Orales Como Acción de Evaluar”
For TCP/IP environments, you might make use of Oracle Database 10g's Easy Connect Naming Method feature, which can eliminate the need for service name lookup in the tnsnames.ora file. We touched on this feature in the Using Oracle SQL*Plus section earlier in this chapter, when discussing some of the ways you can connect to a remote database with SQL*Plus. If you recall, the Easy Connect Naming method enables you to connect to an Oracle database server by simply providing the database user/password combination and the server computer's host name along with two optional parameters, namely, the service name of the database and the port on which the listener will accept connections. Note, however, that you cannot omit the service name when it comes to defining the third parameter of oci_connect:
$dbEasyConn = "//MyDbServer/orcl";
$dbConn = oci_connect($usr,$pswd,$dbEasyConn);
To specify an optional port, you use the following syntax:
$dbEasyConn = "//MyDbServer:1521/orcl";
It is important to realize that orcl in the above examples is not the name of a connect descriptor defined in the tnsnames.ora file, but the service name of the database.
The service name defaults to the global database name—a name consisting of the database name and domain name, which are specified during the installation or database creation.
enabling you to connect to a database server without any configuration.
Issuing an SQL Statement Against the
Database
In the example discussed earlier in this chapter, you used the oci_execute function to execute a SELECT statement against the database. It is important to note that oci_execute's use is not limited to QUERY operations—you can use this OCI8 function to execute any SQL or PL/SQL statements performing QUERY, DML, and DDL operations.
As mentioned, oci_execute returns a Boolean value: true on success and false on failure. In the case of a failure, you likely will want your script to perform certain actions in response. For example, you might use the trigger_error PHP function to either generate an error and stop execution or generate a warning and continue execution. Whether error_trigger stops script execution or not depends on what predefined error level constant you are passing to this function as the second parameter. For example, if you want the script to generate a warning message and continue execution, you must use the E_USER_WARNING predefined constant:
$err = oci_error();
trigger_error(‘Query failed: ‘ . $err[‘message'], E_USER_WARNING);
To terminate execution, you use the E_USER_ERROR constant.
Fetching and Displaying Results
If the oci_execute call returns true, you can then move on to fetching the results. Of course, this makes sense only when you are dealing with a QUERY operation—that is, you are issuing a SELECT statement.
There are several ways to fetch the result data using the PHP OCI8 extension. The example discussed earlier in this chapter demonstrates the use of oci_fetch in conjunction with oci_result:
oci_fetch($stmt);
$rslt = oci_result($stmt, ‘CTIME');
print "<h3>The current time is ".$rslt."</h3>";
You use oci_fetch to fetch the next row from the result data into the internal result buffer. Then, you use oci_result to retrieve the CTIME field's value from the fetched row.
It is important to note that with oci_fetch and oci_result you are not limited to using associative indices—you can use numeric indices as well. So, you might rewrite the above code as follows:
oci_fetch($stmt);
$rslt = oci_result($stmt, 1);
print "<h3>The current time is ".$rslt."</h3>";
While using oci_fetch assumes that you will then use oci_result to retrieve the fetched data from the internal result buffer, there are OCI8 fetch functions that fetch the next row from the result data directly into a PHP array, thus eliminating the need to use oci_result. One of these functions is oci_fetch_array. With this function, you can reduce the above three lines of code to the following two:
$rslt = oci_fetch_array($stmt, OCI_ASSOC);
print "<h3>The current time is ".$rslt[‘CTIME']."</h3>";
Or by using numeric indices:
$rslt = oci_fetch_array($stmt, OCI_NUM);
print "<h3>The current time is ".$rslt[0]."</h3>";
For further discussion on OCI8 fetch functions, see Chapter 2 PHP and Oracle Connection.
Summary
If you have made up your mind to take advantage of the capabilities that the PHP/ Oracle combination provides, the first obvious step is to make sure that you have PHP and Oracle database software installed and working properly. This chapter in conjunction with Appendix A Installing PHP and Oracle Software takes you through the basics of getting your PHP/Oracle development environment installed and configured. You learned that making PHP work with Oracle database is in fact a piece of cake, especially if you employ Zend Core for Oracle—a package that includes all the client libraries needed to work with Oracle from a PHP environment. Every PHP/Oracle application does at least two things: connecting to the database and executing an SQL statement or statements against it. For example, imagine an application that collects user input and then executes an SQL pass-through query to send the data to the database. In practice, however, you normally need to create an application that takes care of two more things: fetching the retrieved data from the database and displaying it to the user. The example discussed in this chapter contains each of the steps mentioned above. Specifically, it shows you how to: connect to the database, issue a query against it, and then fetch and display the
application has to deal with.
Now that you've got a basic understanding of how a PHP/Oracle application works, it's time to move on to more advanced uses. The next chapter deals with some of the most interesting aspects of PHP/Oracle application development and deployment.