1

For example:

$qrInsert = "INSERT INTO DBASE1.DBO.TABLE1 VALUES ('sampVal','sampVal','sampVal')";
odbc_exec($msCon,$qrInsert);

if( 'the query if successfully executed' ){
//then do this

//if not then
}else{
//then do this

}

Is there an easy way to know if it is successfully inserted, or in other cases, updated, and deleted succesfully?

Thanks

1
  • 2
    Just simply look at the return value of your call: odbc_exec Commented Jun 7, 2013 at 7:32

4 Answers 4

8

Try like

if(odbc_exec($msCon,$qrInsert))
{
    echo 'Executed Successfully';
} else {
    echo 'Error in execution';
}

odbc_exec only will return true if the query executed successfully,or else return false if it is not

Sign up to request clarification or add additional context in comments.

2 Comments

+1 - PHP manual - Returns an ODBC result identifier if the SQL command was executed successfully, or FALSE on error
is it better if I put it on a variable like the other answers?
1
if (odbc_exec($msCon,$qrInsert)){
// do this
}
else{
// do that
}

Comments

0

just replace your code with

 $qrInsert = "INSERT INTO DBASE1.DBO.TABLE1 VALUES ('sampVal','sampVal','sampVal')";
  if( odbc_exec($msCon,$qrInsert); )
     {
       //then do this
       //if not then
     }
 else
    {
     //then do this
    }

Comments

0

It Return 0 or 1 depends on failure or success of your query.You Can store result of "odbc_exec" in a variable & compare it in 'If','Else' condition.Benefit of storing in a variable is ,you can use it where ever you want .
i.e.
$query_result = odbc_exec($msCon,$qrInsert);
if($query_result)
echo 'Executed Successfully';
else
echo 'Execuion Error';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.