Page 1 of 1
pear DB not executing an insert query
Posted: Wed Sep 27, 2006 12:40 pm
by Burrito
I have a query that looks something like this:
Code: Select all
$qry = "INSERT INTO `myTable`
SET
`myField` = '".$this->dbCleanse($someField)."',
`myField2` = '".$this->dbCleanse($someField2)."'";
then I'm trying to execute that query using pear DB like this:
Code: Select all
$stm = $this->dbConnection->query($qry);
but it's not performing my insert. If I echo my query out and then manually insert it, it runs fine. I'm new to pear DB and am not sure I'm doing this right. I really don't want to use the prepare() and execute() methods because this isn't going to take any extraneous arguements. Can I not use the query() method to perform an insert query?
Posted: Wed Sep 27, 2006 12:46 pm
by Weirdan
check the return value of db::query() to see if it's PEAR_Error instance.
Posted: Wed Sep 27, 2006 12:57 pm
by Burrito
Code: Select all
if(DB::isError($stm))
{
echo "problem!";
}
this isn't yeilding anything
nor is:
Posted: Wed Sep 27, 2006 1:09 pm
by Weirdan
var_dump($stm)
Posted: Wed Sep 27, 2006 1:15 pm
by Burrito
Posted: Wed Sep 27, 2006 1:34 pm
by wtf
what is
for????
you should be able just to instantiate db object and call a method on it
$db = new DB;
$db->query();
what version of PEAR::DB is this???
Posted: Wed Sep 27, 2006 1:34 pm
by volka
Now guess what
Code: Select all
<?php
require 'DB.php';
var_dump(DB_OK);
?>
prints

Posted: Wed Sep 27, 2006 1:42 pm
by Burrito
yields the same thing:
but nothing is getting inserted into my table.
Posted: Wed Sep 27, 2006 1:43 pm
by wtf
Posted: Wed Sep 27, 2006 1:47 pm
by volka
also try
Code: Select all
$stm = $this->dbConnection->query($qry);
if (PEAR::isError($stm)) {
die('error: '.$stm->getMessage());
}
else if ( DB_OK===$stm ) {
echo '<div>', $this->dbConnection->affectedRows(), " records have been inserted</div>\n";
}
else {
die('weird: '.$stm);
}
Posted: Wed Sep 27, 2006 1:58 pm
by Burrito
echoing lastquery didn't do anything.
Volka, yours resulted in:
"records have been inserted"
it didn't indicate a number of rows being inserted, nor did it actually insert a row.
wtf?
edit: I mean wtf as in the real meaning of wtf...not you wtf

Posted: Wed Sep 27, 2006 2:07 pm
by wtf
I think you may have it set up all wrong.
where does dbConnect() comes from???
all you had to do with pear is this
config.php
Code: Select all
require_once( 'DB.php' );
$db =& DB::connect( dbdriver://user:password@localhost/database );
$db->setFetchMode( DB_FETCHMODE_ASSOC );
if ( PEAR::isError( $db ) )
{
die( $db->getMessage( ) );
}
from there
Code: Select all
$result = $db->query('insert into table values( ?, ?, ?)', array( $value, $value, $value));
if ( PEAR::isError( $result ) )
{
echo $result->getMessage() );
echo $db->last_query;
}
Posted: Wed Sep 27, 2006 2:16 pm
by Burrito
uggh...I got it working with prepare() and execute()...but am really frustrated that I couldn't make it work with the query() method.
shouldn't the query() method work with inserts?
Posted: Wed Sep 27, 2006 2:18 pm
by wtf
Posted: Wed Sep 27, 2006 2:22 pm
by Burrito
weirdness.
I guess I'm going to chalk it up to voodoo then. Maybe when I get some more time I'll work it further, but I really need to get this out the door this afternoon and I have it working with prepare() and execute().
thx for trying everyone
