All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
  Print view

how to catch err in $recs = $db->getrows($qry);
Author Message
PostPosted: Sun Sep 24, 2017 6:42 pm 
Regular
User avatar
Offline

Joined: Thu Aug 25, 2011 9:31 pm
Posts: 303
Location: Mumbai, India
how to catch err in $recs = $db->getrows($qry);
==================================
i have simple single table node.

in postadd() - i m inserting in another table which has a constraint bcoz of which insert may fail.
I wish to catch that error - that the insert failed. How to do it?
Code:
:
function postadd()
{

:
:
//insert in another table
      $qry = "INSERT INTO va_locked_slot (va_emp_id,slot_number,capacity_req_date,capacity_req_tm_fr,booking_mode
                                    ,created_by,created_date, request_id
                                   )";
      $qry .= " VALUES ('$operator', '$slot_number','$capacity_req_date','$capacity_req_tm_fr', '$booking_mode'
                            ,'$userid', '$created_date', '$request_id'
                            )"  ;

            $recs = $db->getrows($qry); >>>>> how to catch constraint error here

/*
table stru for refernece
DROP TABLE IF EXISTS va_locked_slot;
CREATE TABLE va_locked_slot
(
va_emp_id INT(11) NOT NULL,
slot_number INT(11) NOT NULL,             -- this can be dropped suggested by dhananjay acc primary key will change
capacity_req_tm_fr VARCHAR(10) NOT NULL,  -- (x 11:15, 11:30 etc) addn suggested by dhananjay acc primary key will change
capacity_req_date VARCHAR(20) NOT NULL,
booking_mode VARCHAR(10) ,               -- addn suggested by dhananjay
created_date VARCHAR(20),
created_by INT(11),
request_id INT(11),
PRIMARY KEY(va_emp_id,capacity_req_tm_fr,capacity_req_date)
);
*/



}


Top
 Profile  
 

Re: how to catch err in $recs = $db->getrows($qry);
PostPosted: Mon Oct 02, 2017 3:24 pm 
Regular
User avatar
Offline

Joined: Thu Aug 25, 2011 9:31 pm
Posts: 303
Location: Mumbai, India
$db->m_haltonerror = false; requried

Code:

      $db = &atkGetDb();

    //30.Sep.2017 refer atk/db/classatkdb.inc
      $haltonerror_org = $db->m_haltonerror;
      $db->m_haltonerror = false; //#IMP#otherwise Uniq Key Constraint error is thrown ut with abort
       :
       :
      $flag = true;
      //-- 1st qry
      $qry = "INSERT INTO qry (material_type) VALUES ('rollbacktest')";
      $result = $db->getrows($qry);
      //if ($db->hasError() && $db->getErrorType() != "user")
      if ($db->hasError())
        {
          //triggerError($record, null, '', $db->getErrorMsg());
          $msg1="Qry1False".$db->getErrorMsg();
          $flag = false;  //mark as error
        }

      //-- 2nd qry
          :
          :

    $db->m_haltonerror = $haltonerror_org; //#IMP# RESTORE orgval otherwise Uniq Key Constraint error is thrown ut with abort



Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group