Jump to content

Pear query just not working...


mschrank

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
Link to comment
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.
Link to comment
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.