Sentora Support Forums
ListCurrentMailboxes($mid) in controller.ext.php - Printable Version

+- Sentora Support Forums (https://senforums.mach-hosting.com)
+-- Forum: General Forums - (Non-Sentora Support) (https://senforums.mach-hosting.com/forumdisplay.php?fid=1)
+--- Forum: Sentora Development (https://senforums.mach-hosting.com/forumdisplay.php?fid=54)
+--- Thread: ListCurrentMailboxes($mid) in controller.ext.php (/showthread.php?tid=2468)



ListCurrentMailboxes($mid) in controller.ext.php - Vedran B - 01-12-2016

file: /etc/sentora/panel/modules/mailboxes/code/controller.ext.php

I don't see why there are 2 sql querys executed here:

PHP Code:
static function ListCurrentMailboxes($mid)
 
   {
 
       global $zdbh;
 
       $sql "SELECT * FROM x_mailboxes WHERE mb_id_pk=:mid AND mb_deleted_ts IS NULL ORDER BY mb_address_vc ASC";
 
       //$numrows = $zdbh->query($sql);


---> QUERY1 start here
        
        $numrows 
$zdbh->prepare($sql);
 
       $numrows->bindParam(':mid'$mid);
 
       $numrows->execute();

---> 
IF it returns anything then execute again to parse
        if 
($numrows->fetchColumn() <> 0) {
 
           $sql $zdbh->prepare($sql);
 
           $sql->bindParam(':mid'$mid);
            
$res = array();
 
           $sql->execute();
 
           
            while 
($rowmailboxes $sql->fetch()) {
 
               if ($rowmailboxes['mb_enabled_in'] == 1) {
 
                   $ischeck "CHECKED";
 
               } else {
 
                   $ischeck NULL;
 
               }
 
               $res[] = array('address' => $rowmailboxes['mb_address_vc'],
 
                   'created' => date(ctrl_options::GetSystemOption('sentora_df'), $rowmailboxes['mb_created_ts']),
 
                   'ischeck' => $ischeck,
 
                   'id' => $rowmailboxes['mb_id_pk']);
 
           }
 
           return $res;
 
       } else {
 
           return false;
 
       }
 
   



couldn't it be solved like this:

PHP Code:
static function ListCurrentMailboxes($mid)
 
   {
 
       global $zdbh;
 
       $sql "SELECT * FROM x_mailboxes WHERE mb_id_pk=:mid AND mb_deleted_ts IS NULL ORDER BY mb_address_vc ASC";
 
       
        $numrows 
$zdbh->prepare($sql);
 
       $numrows->bindParam(':mid'$mid);
 
       $numrows->execute();

 
       if ($numrows->fetchColumn() <> 0) {
 
           $res = array();
 
           
            while 
($rowmailboxes $numrows->fetch()) {
 
               if ($rowmailboxes['mb_enabled_in'] == 1) {
 
                   $ischeck "CHECKED";
 
               } else {
 
                   $ischeck NULL;
 
               }
 
               $res[] = array('address' => $rowmailboxes['mb_address_vc'],
 
                   'created' => date(ctrl_options::GetSystemOption('sentora_df'), $rowmailboxes['mb_created_ts']),
 
                   'ischeck' => $ischeck,
 
                   'id' => $rowmailboxes['mb_id_pk']);
 
           }
 
           return $res;
 
       } else {
 
           return false;
 
       }
 
   



RE: ListCurrentMailboxes($mid) in controller.ext.php - TGates - 01-12-2016

@[Me.B] @[jacobg830]


RE: ListCurrentMailboxes($mid) in controller.ext.php - Me.B - 01-12-2016

Yep that should be one query no need to execute twice once to get rows number then to assign it to objects...

You should post a pull here:

https://github.com/sentora/sentora-core/blob/master/modules/mailboxes/code/controller.ext.php

M B