O'Reilly logo

PHP Programming with PEAR by Stoyan Stefanov, Carsten Lucke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using MDB2

Once you've connected to your database and have set some of the options and the fetch mode, you can start executing queries. For the purpose of the examples in this chapter, let's say you have a table called people that looks like this:

id

name

family

birth_date

1

Eddie

Vedder

1964-12-23

2

Mike

McCready

1966-04-05

3

Stone

Gossard

1966-07-20

A Quick Example

Here's a quick example, just to get a feeling of how MDB2 can be used. You'll learn the details in a bit, but take a moment to look at the code and see if you can figure it out yourself.

<?php require_once 'MDB2.php'; // setup $dsn = 'mysql://root:secret@localhost/mdb2test'; $options = array ('persistent' => true); $mdb2 =& MDB2::factory($dsn, $options); $mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required