Thursday, September 2, 2010

PHP is so much easier to get something out than Java. Less typing, a simple example is a db access.

require_once('MDB2.php');
$dsn = 'mysql://root:workflow@localhost';
$mdb2 = & MDB2::factory($dsn);

if(PEAR::isError($mdb2)){
echo ("error connecting to db\n");
echo($mdb2->getMessage().' - '.$mdb2->getUserInfo());
}
echo("connected !!! yay....\n");
$setDB = 'use test';
$dbSet = $mdb2->query($setDB);
if(PEAR::isError($dbSet)){
echo("mysql db not set\n");
}else{
echo("db test selected\n");
}
$query = 'SELECT * from test';
$result = $mdb2->query($query);
if(PEAR::isError($result)){
echo($result->getMessage().'-'.$result->getUserInfo());

}else{
echo("query results returned\n");
}
$array = $result->fetchRow();
$result->free();
var_dump($array);


The programming idioms are so easy to use and the source is available. This is so easy to figure out, less than 10 minutes after a websearch. Cut and paste the code then just add queries and use the MDB2 error handler. The code is self explanatory, no need to look at any documentation on how library functions work or where they are. A good lesson for XCode and Java libraries.

No comments:

Post a Comment