PHP Webhost操作检查

时间:2018-03-14 06:08:35

标签: php android react-native error-handling web-hosting

我想在执行更新功能时执行检查PHP Webhost是否完整,如果一切正常则发送通知并让应用程序知道操作正常。

基本上我想知道PHP中的查询是否有效并使用我的应用程序来通知用户。

有没有办法或方法呢?

我使用此方法从我的React Native App

中的PHP中获取数据
RecipeUpdation = () =>{
   const { ID }  = this.state ;
   const { Name }  = this.state ;
   const { Type }  = this.state ;
   const { Ingredient }  = this.state ;
   const { Step } = this.state ;

   return fetch('https://www.update.php', {
       method: 'POST',
       headers: {
         'Accept': 'application/json',
         'Content-Type': 'application/json',
       },
       body: JSON.stringify({

         RecipeID : ID,
       RecipeName : Name,
       RecipeType : Type,
       RecipeIngredient: Ingredient,
       RecipeStep: Step

       })

     }).then((response) => response.json())
           .then((responseJson) => {
           }).catch((error) => {
             console.error(error);
           });

       }

1 个答案:

答案 0 :(得分:0)

基本上我们可以通过检查查询执行状态来验证PHP中的操作是否成功。执行检查的一种非常基本的方法是使用If Else查看查询函数是返回True(成功)还是False(失败)。您也可以随时通过JsonResponds返回一些消息。

这里有一些示例代码用于PHP检查并返回一些消息:

// Using If Else to Check if operation Success or Not
if(mysqli_query($connection,$Your_Query)){

$MSG = 'Success' ;

// Convert message into Json format first
$json = json_encode($MSG);

// This is where it return the message to Application.
 echo $json ;

 }
 else{

 $MSG = 'Failed' ;

 $json = json_encode($MSG);

 echo $json ;
 }

在您的应用程序代码中,您已经有了实现来检索PHP代码中已JsonResponds的{​​{1}}(消息),我建议使用一个简单的方法{{1}弹出React Native Application中的消息,通知用户操作状态。

echo

希望这会有所帮助。