[pLog-svn] db vs pdb confusion...

Paul Westbrook paul at westbrooks.org
Sat Jan 27 22:30:08 EST 2007


Hello,
    Would this do what you want?

$query = "SELECT address ".
"FROM {$prefix}subscribe ".
"WHERE active=1 AND ".
"type=".$type." AND " .
"objid IN (";

foreach($ids as $id)
     $query .= "$id, ";
$query .= "0)";


This should create a where clause like "WHERE active = 1 AND type =  
<type> AND objid IN ( 1, 2, 3, 0)"

--Paul

On Jan 27, 2007, at 5:22 PM, Jon Daley wrote:

> I am not sure how to convert this to a buildSelectQuery()
>
>          $query = "SELECT address ".
>              "FROM {$prefix}subscribe ".
>              "WHERE active=1 AND ".
>              "type=".$type." AND (";
>          foreach($ids as $id)
>              $query .= "objid=$id OR ";
>          $query .= "objid=0)";
>
> The WHERE condition has a nested OR, inside an AND.
> Is that possible to do?  Is there documentation or some place to  
> look for
> these sorts of examples?
>
> On Sat, 27 Jan 2007, Jon Daley wrote:
>
>> 	Yes, I just figured that out - I don't know what I was thinking.
>> It does look like there is too much code in db.class.php - ie. why  
>> do the
>> buildWhereCondition, buildUpdateQuery, etc. exist in that class?
>> Shouldn't the pdb classes only be used?  Maybe that is just for  
>> backward
>> compatibility?
>>
>>  On Sun, 28 Jan 2007, Oscar Renalias wrote:
>>
>>> Db::getDb() returns a reference to the right database driver,
>>> currently PDbMySQLDriver only so you can call the
>>> PDbDriverBase::Affected_Rows() in that object to get what you're
>>> looking for.
>>>
>>> On 28 Jan 2007, at 01:57, Jon Daley wrote:
>>>
>>>> I haven't ever quite understood how all the database stuff works.
>>>>
>>>> I have a function that I was typing the mysql directly, and I
>>>> thought that
>>>> perhaps I should use the Db::buildUpdateQuery instead.  Is that the
>>>> right
>>>> thing to do?
>>>>
>>>> What I am missing is I don't know how to get to the Affected_Rows()
>>>> function, that exists in mysqldriver, but not mysqlrecordset.
>>>>
>>>>
>>>>
>>>>      function confirmSubscription($confirmation){
>>>>          include_once( PLOG_CLASS_PATH."class/database/
>>>> db.class.php" );
>>>> //        $prefix = Db::getPrefix();
>>>> //        $query = "UPDATE {$prefix}subscribe ".
>>>> //            "SET active=1, confirm=NULL ".
>>>> //            "WHERE confirm='$confirmation'";
>>>>          $db =& Db::getDb();
>>>>          $query = Db::buildUpdateQuery("subscribe",
>>>>                                        array("active" => 1,
>>>>                                              "confirm" => NULL),
>>>>                                        array("confirm" =>
>>>> $confirmation));
>>>>          if(!$db->Execute($query))
>>>>              return false;
>>>>
>>>>              // TODO: check affected_rows, and make sure
>>>>              // that it is at least 1.
>>>>          return true;
>>>>      }
>>>>
>>>>
>>>> --
>>>> Jon Daley
>>>> http://jon.limedaley.com/
>>>>
>>>> To be upset over what you don't have is to waste what you do have.
>>>> -- Unknown
>>>> _______________________________________________
>>>> pLog-svn mailing list
>>>> pLog-svn at devel.lifetype.net
>>>> http://limedaley.com/mailman/listinfo/plog-svn
>>>>
>>>
>>> _______________________________________________
>>> pLog-svn mailing list
>>> pLog-svn at devel.lifetype.net
>>> http://limedaley.com/mailman/listinfo/plog-svn
>>>
>>
>> -- 
>> Jon Daley
>> http://jon.limedaley.com/
>>
>> There are really only two bases: 2 and e.
>> -- Michael Brian McElroy
>> _______________________________________________
>> pLog-svn mailing list
>> pLog-svn at devel.lifetype.net
>> http://limedaley.com/mailman/listinfo/plog-svn
>>
>
> -- 
> Jon Daley
> http://jon.limedaley.com/
>
> Any time you get a mouthful of hot soup,
>    the next thing you do will be wrong.
> -- Zall's First Law
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn

--
Paul Westbrook
paul at westbrooks.org
<http://www.westbrooks.org>




More information about the pLog-svn mailing list