First I would like to suggest about the use of this package . That would be useful only when you are developing application from start. Its all about your journey of programming from your first step to the last step. Recently I came to the use of database other than MySql with PHP.
How many databases you know?
What else, every database have different way for connection, different function, different way to perform DB tasks. MDB2 package is really a good way to work with different databases. Sometimes our application need logic beyond the power of existing database, then what will you do? Will you change your database? Then what about all the classes or files that you have built to handle data!!!!
MDB2 is the package which gives you the facility to tackle this problem. Install the driver for that particular DB using PEAR command and change the name of driver in your database file. What else, now use the power of your new database.
Following is the simple example of that:
// Use the details of your database at the place of given dummy values :)
$db_driver="mysql"; // only need to change the db driver if other need to be used
$user="user;
$password="password";
$host="host";
$database_name="database_name";
$url=$db_driver."://".$user.":".$password."@".$host."/".$database_name;
require_once("MDB2.php");
$con = MDB2::factory($url);
if(PEAR::isError($con)) {
die("Error while connecting : " . $congetMessage());}
else{echo "Connection is done"."
";}
$sql = "SELECT * FROM users";
$resultset = $con->query($sql);if(PEAR::isError($resultset))
{ die('Failed to issue query, error message : ' . $resultset->getMessage());}
while($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC))
{foreach($row as $field => $value)
{ echo "$field / $value \n";}}?>
Subscribe to:
Post Comments (Atom)
1 comment:
Hello friends... currently I am working on Magento which is using PDO library for database access... Its really worth to study this library..... cheers for programming
Post a Comment