Advanced PEAR::DB: Prepared Statements : PEAR « Utility Function « PHP






Advanced PEAR::DB: Prepared Statements

 
include_once('DB.php');
    $db = DB::connect("mysql://user:password@localhost/phpdb");

    if (DB::isError($db)) {
            print $db->getMessage( );
            exit;
    } else {
            $data = array(
                    array("Gabor", 25),
                    array("Elisabeth", 39),
                    array("Vicky", 19)
            );

            $prep = $db->prepare("INSERT INTO people VALUES (?, ?);");

            while(list($var, $val) = each($data)) {
                    print "Adding element $var\n";
                    $db->execute($prep, $val);
            }
    }

    $db->disconnect( );
  
  








Related examples in the same category

1.PEAR::DB
2.Quick PEAR::DB Calls