PEAR DB, prepare(), and placeholders

From: Date: Mon, 02 Jul 2001 20:34:36 +0000
Subject: PEAR DB, prepare(), and placeholders
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-529@lists.php.net to get a copy of this message
I asked this on PHP-DB with no response so far, so I'll ask here, too... Please excuse the cross-post. I'm using PHP 4.0.6, but the way. Question 1: When using PEAR DB, are you supposed to be able to use a prepared statement multiple times? I would suppose yes, but when I execute the code below, the second use of the prepared statement results in an error: $stmt = $conn->prepare ("INSERT INTO abc (i, c) VALUES (?, ?)"); if (DB::isError ($stmt))
    die ("prepare() failed: " . $stmt->getMessage () . "\n");
$result = $conn->execute ($stmt, array (4, "d")); if (DB::isError ($result))
    die ("execute() failed: " . $result->getMessage () . "\n");
$result = $conn->execute ($stmt, array (5, "e")); if (DB::isError ($result))
    die ("execute() 2 failed: " . $result->getMessage () . "\n");
The error message from the script is: execute() 2 failed: DB Error: syntax error I'm using MySQL. The queries that show up in the MySQL log file are:
23304 Query       INSERT INTO abc (i, c) VALUES ('4', 'd')
23304 Query       Object
Looks to me like $stmt is being munged? Question 2: How to you bind a NULL value to a placeholder? In DBI, you use undef to stick a NULL into a query; in PEAR DB, I tried both null and an unset variable, with the result that an empty string was placed into the query string in both cases. -- Paul DuBois, paul@snake.net

« previous php.pear.dev (#529) next »