Jump to content


Photo

Pear query just not working...


  • Please log in to reply
3 replies to this topic

#1 mschrank

mschrank
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 July 2006 - 07:03 PM

$pear_dsn = xxxxx (confidential)

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


#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 05 July 2006 - 07:31 PM

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? 
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 mschrank

mschrank
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 July 2006 - 07:53 PM

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.

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 05 July 2006 - 08:17 PM

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!
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users