i have php script pipe through mail,
class mailtest { // (some code here) private function savetodb() { // (some code here) $select = $this->pdo->query("select * tbl_reques terminal_id = $term , request_status ='' "); $select = $select->fetchall(); if (count($select) > 0) { echo "call exist (discard)"; } else { $select_tech = $this->pdo->query("select * tbl_email terminal_id = $term"); $select_tech = $select_tech->fetchall(); // (some code here) } } private function sendemail() { $this->today = time(); $this->maildate = date("y-m-d h:i:s", strtotime('-5 minutes', $this->today)); $select = $this->pdo->query("select * tbl_reques maildate >= '$this->maildate' "); // code here mail($this->from_email, $this->subject, $newmsg, $headers); } }
the problem time condition false i.e echo "call exist (discard)";
code not go next function. i.e program halt. pls there way if condition not met, program jump next function continuation of execution. or possible use goto statement. pls best way handle in php. thanks
you have couple option this. can return
@ point of failure. exit function @ point , whatever next in script being ran. sure clean before return.
if(count($select) > 0) { echo "call exist (discard)"; //clean if needed return; //you return message //or error code , have //evaluation based on that. } else { // or passes }
you call next function bad flow in opinion
if(count($select) > 0) { echo "call exist (discard)"; //clean if needed $this->sendemail(); } else { // or passes }
the reason bad if in script have
$mailtest = new mailtest(); $mailtest->savetodb(); $mailtest->sendemail(); //when above fails called twice.
you likewise throw exception
if(count($select) > 0) { echo "call exist (discard)"; throw new exception("call exist (discard)"); } else { // or passes }
now need use try
, catch
$mailtest = new mailtest(); try { $mailtest->savetodb(); catch (exception $e){ //do $e //clean failure if needed } $mailtest->sendemail();
there finally
block run in cases catch stops script.
Comments
Post a Comment