=====
CS 328 - Week 10 Lecture 2 - 2026-04-01
=====
=====
TODAY WE WILL
=====
* announcements
* CONTINUING whirlwind intro to use PHP and OCI to connect
to an Oracle DB
* prep for next class
=====
* should be working on Homework 8!
* deadline: 11:59 pm on Friday, April 3
* submit files OFTEN, THROUGHOUT the week!
* Should also start reading and working through the activities
in zyBooks Chapter 5 - PHP Fundamentals
* IT IS advising time for SUMMER 2026/FALL 2026!
* preregistration for FALL 2026 begins at your
registration appointment in your student center
(sometime between April 13 - April 24)
=====
SIDE NOTE: if you are considering taking Humboldt courses in SUMMER 2026
=====
* registration for SUMMER 2026 opens for ***EVERYONE*** on APRIL 13!!!!
* from:
https://www.humboldt.edu/student-financial-services/summer-term-2026
"For the 2026 Summer term, the university is guaranteeing 3 units,
if enrolled in 6 or more units, will be covered for all continuing
matriculated undergraduate students. This will cover 3 units of
the tuition charge and does not include coverage of mandatory
campus-based fees or the additional non-resident tuition if
applicable."
* see the above link for more information!
=====
CONTINUING our intro to using OCI
with PHP to connect to Oracle
=====
* OCI function oci_connect expects 5 arguments,
and returns a connection OBJECT that can be used
by PHP on the application tier to
request that the DBMS on the data tier
DO actions that it requests;
* a string username
* a string password
* a string connection string
* a string encoding
* an int session mode
* when you are done with a connection,
CLOSE it IN the current PHP document's response
BEFORE you leave that PHP document!!
using:
oci_close($conn); /* using your connection object of course */
=====
once you have a connection...
=====
=====
...get a statement object!
=====
* using OCI function oci_parse
* 1st argument: a connection object
2nd argument: a string containing the desired data-tier
statement to be executed (eventually)
* IMPORTANT: do NOT include a semicolon WITHIN this
string!
and if successful, it returns as statement object
=====
once you have a statement object,
IF you have any bind variables, you would bind them to
values;
then, you would execute the result
=====
* ...and you execute using oci_execute
1st argument: the statement object
2nd argument: OCI_DEFAULT
=====
what if your statement was a SELECT?
...then you fetch each row in that result,
and grab the desired values from that row
=====
* fetch the next row using:
oci_fetch
* with the statement object as its argument
This returns something truthy if it succeeded,
and something falsey if not!
(so it is great for iterating through a select's results:
while (oci_fetch($my_stmt) )
{
...
* (although you would just call oci_fetch ONE time,
with NO loop, for a select statement guaranteed to
return exactly ONE row, such as a select projecting
aggregate function calls when NO group-by clauses
are involved...)
=====
once you have fetched a row from the query result...
=====
* you can access values in the currently-fetched row using
oci_result
* 1st argument: the statement object
* 2nd argument:
EITHER a string with the projected column name from
that select,
OR its 1-based position in the project row
* IMPORTANT: if you use a second argument of
a string with the projected column name,
THAT STRING MUST BE ALL-UPPERCASE, even if NOT written
that way in the query string!!!!
* try it: in a copy of 328lect10-2.php,
CHANGE:
<?= oci_result($empl_stmt, "EMPL_LAST_NAME") ?>,
to:
<?= oci_result($empl_stmt, "empl_last_name") ?>,
...and SEE the errors that result!
* related: if your SELECT statement projects a
column alias, you need to use THAT column alias
in the oci_result's 2nd argument string if using
that version of oci_result
* unquoted column alias? you DO need to write
its name in all-uppercase in that string
* quoted column alias? you need to write its
name matching its case in the query!
* (when I tried this, I used SINGLE
quotes for the query string so I could
have DOUBLE quotes within it for
that particular style of column alias!)
=====
once you have fetched all the rows,
and are finished with your statement object...
=====
* it is considered good practice to FREE your statement
when you are done with it, using
oci_free_statement($desired_stmt);
=====
and when done with your connection, CLOSE IT!
=====
* and, of course CLOSE your connection when you are done,
using oci_close with your connection object as its argument,
BEFORE your PHP document completes its response!
* see our first two examples using this:
* try-oracle.php
* 328lect10-2.php