Jump to content

Archived

This topic is now archived and is closed to further replies.

mschrank

Pear query just not working...

Recommended Posts

$pear_dsn = [i]xxxxx (confidential)[/i]

require_once 'DB.php';

$options = array(
    'debug'      => 2,
    'portability' => DB_PORTABILITY_ALL,
);

$db =& DB::connect($pear_dsn, $options);
if (PEAR::isError($db)) {
    die($db->getMessage());
}

$db->setFetchMode(DB_FETCHMODE_ASSOC);

$sql = "delete from child_basic where child_id = '". $_GET['child_id']. "'";

# send the query

$query = $db->query($sql);
if (PEAR::isError($db)) {
    die($db->getMessage());
}

...

This query has no effect whatsoever, but works when the SQL is echo'd and cut and pasted into the mysql client.

Totally confused.

-Matt

Share this post


Link to post
Share on other sites
I'm not sure what the problem is, are you sure the query is being executed by the script?  Have you tried echoing out the something just before and just after you execute it? 

Share this post


Link to post
Share on other sites
Thanks for your reply.

Yes, I have tried "echo $sql;" and I get a statement which works when cut and pasted directly into my postgresql client. So there is no problem with the sql statement of the building of it.

It seems to me that the query function of the DB class is not working. Yet I have no idea why and I get no error messages.

Share this post


Link to post
Share on other sites
Well, there are only two things I can think of.  First, did you try to print something after the $db->query($sql);  If so did it print out or not?  I wasn't sure if you printed out the sql before or after executing it.  If the stuff doesn't print out afterwards then there is some sort of error there.  Second, I know with MDB2, which is the successor to DB, you have to have the MySQL drive installed.  I'm not sure where to find it, though PEAR is probably a good place to start looking.  At any rate, I couldn't do any queries until I added the file to a directory...

I haven't used DB in a while, but I think what you have is right, so try what I suggested above, and if that doesn't work you can always try MDB2 or just your own script (though that will mean giving up features).

One last thing, try changing the MySQL keywords to all caps, DELETE, FROM and WHERE.  I'm not sure if that will do anything, but I've found some wierd MySQL behaviour before based off of similar stuff.  For instance, recently I had a case like this one where I would print out the sql and it would execute if entered directly, but fail to execute if done through PHP.  The sql was using a COUNT(*), the cause of the problem was a space between COUNT and ()... For some reason it worked through PHPmyAdmin but not through my script!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.