Query not return any result in logic hook but query work in MySQL workbench

My code in Cases module hook:

$sql = "select c.id from cases c
        left join emails e on e.parent_id = c.id and e.parent_type = 'Cases'
        left join emails_text et on et.email_id = e.id
        where c.id = '{$focus->id}' and et.to_addrs like '%_string_%'";
$result = $focus->db->query($sql,true);
$check =  $focus->db->fetchByAssoc($result);
if(!empty($check)){
     $GLOBALS['log']->fatal("Hello World ".$check);
}

I search solution in google many people suggest to using SugarQuery but it not more complex for my query or I do wrong with my code?

Please suggest me for solution.

Sugar 7.6 Ent

Thanks,

M

Parents Reply
  • Thanks,

    But I have already one I try with another method by using CURL and return JSON then I decode JSON into value.

    <?php

    include('../config.php');

    //JSON function...

    mysql_connect($sugar_config['dbconfig']['db_host_name'], $sugar_config['dbconfig']['db_user_name'], $sugar_config['dbconfig']['db_password']) or die(mysql_error());

    mysql_select_db($sugar_config['dbconfig']['db_name']) or die(mysql_error());

    mysql_query("SET NAMES UTF8");

    unset($sql);

                            $sql = "SELECT count(*) as 'cc' FROM cases c ".

                                    "LEFT JOIN emails e ON e.parent_id = c.id and e.parent_type = 'Cases' ".

                                    "LEFT JOIN emails_text et ON et.email_id = e.id ".

                                    "WHERE c.id = '{$id}' AND et.to_addrs LIKE '%_emailaddr_%' ";

            $result = mysql_query($sql);

                    while($row = mysql_fetch_array($result)){

                    $Json->add('cc',$row['cc']);

            }

    When I run It's work perfect but when I put in logic hook not work.

    copy CURL url and run return 1 but when using logic hook return 0 or It might not any data.

Children
No Data