PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 12:40 pm
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?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Sep 27, 2006 12:46 pm
check the return value of db::query() to see if it's PEAR_Error instance.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 12:57 pm
Code: Select all
if(DB::isError($stm))
{
echo "problem!";
}
this isn't yeilding anything
nor is:
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Sep 27, 2006 1:09 pm
var_dump($stm)
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 1:15 pm
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Wed Sep 27, 2006 1:34 pm
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???
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Sep 27, 2006 1:34 pm
Now guess what
Code: Select all
<?php
require 'DB.php';
var_dump(DB_OK);
?>prints
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 1:42 pm
yields the same thing:
but nothing is getting inserted into my table.
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Wed Sep 27, 2006 1:43 pm
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Sep 27, 2006 1:47 pm
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);
}
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 1:58 pm
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
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Wed Sep 27, 2006 2:07 pm
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;
}
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 2:16 pm
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?
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Wed Sep 27, 2006 2:18 pm
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Sep 27, 2006 2:22 pm
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