Jonas Ivy V. Imperial
Jonas Ivy V. Imperial

Reputation: 125

php: How will I know if the sql query is successfully executed

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

Upvotes: 1

Views: 3029

Answers (4)

Mukesh Swami
Mukesh Swami

Reputation: 415

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';

Upvotes: 0

Rajeev Ranjan
Rajeev Ranjan

Reputation: 4142

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
    }

Upvotes: 0

Bere
Bere

Reputation: 1747

if (odbc_exec($msCon,$qrInsert)){
// do this
}
else{
// do that
}

Upvotes: 1

GautamD31
GautamD31

Reputation: 28763

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

Upvotes: 8

Related Questions