« A Little String FUN | Main | LOOPing for Data - Part II »

November 10, 2005

Out With the Solaris/Oracle Box, in With PHP

Well, our group project of building the Solaris box and installing Oracle 10g thereon has hit a major snag. Shaun got "pulled" to work on another project and so did the hardware! We were disappointed, but will take up with the Oracle install when we can.

In the mean time, Dale and I decided to press on with PHP. Using my primary programming strategy - stealing from someone else - I "borrowed" some code from Ron who is way ahead of us in PHP. In this way, Dale and I were able to connect to AERO through PHP, and run a simple select statement. Here's what the code looks like:

require_once 'DB.php';
//This is a call to the php module that does database communication - kind of like an include file.

$dsn = 'oci8://username:password@sid';
//Set a variable with the Oracle connection string information.

$dboptions = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
//A bit of fanciness Ron uses to implement portability. One of the main uses for this is to implement associative arrays (another new term).

$dbconn = DB::connect($dsn, $dboptions);
//do it - connect up using the variables we created.

if (PEAR::isError($dbconn)) {die ($dbconn->getMessage());} #if we could not connect, quit the whole file and print message

$sql = "select * from um";
$res = $dbconn->query($sql);
//Set the $sql string and run the query. Could also put the query inside the query() brackets.

if (PEAR::isError($res)) { die ($res->getMessage()); }
//If the query errs, capture the error and quit.

print "Num rows:" . $res->numRows();
//TaDa - this is what printed for us - Num rows: 39.

while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
$ums[$row['abbr']] = $row['description'];
#print "$row[abbr] - $row[description]
"; #debug
}
//What the heck, fill an array with the query results. Next time figure out how to use this.....

$res->free(); #get rid of the query now that we have the data into the $ums array

$dbconn->disconnect();
//close connection.

There it is. Enough time for Dale to eat a donut, too.

We all agreed that PHP is not going to be useful unless we can master DB tasks with it. In talking to Mike Ellis, he raised an interesting question - why would we use PHP, which is not compiled, rather than PL/SQL, which is compiled?? Good question. I don't know.


Posted by rossm at November 10, 2005 12:51 PM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?