duanbei7035 2018-01-20 16:12
浏览 38

使用Android应用程序时无法加载数据库

I am using one database for android application and website. So admin can update website and android application through one admin panel and at once time. For android application, database is connected through API. The problem is that android application run smoothly only if I drop table that are not associated with application. Database contains 15 table. Among them 3 tables are jointly used for android application and website. If I drop rest of tables except these 3 tables, android application run smoothly. But If I don't drop other tables, android application hardly fetch data. At same time, if I run website (while application loading) website can't load.

This site can’t be reached
........took too long to respond.
ERR_CONNECTION_TIMED_OUT

I think problem in following code.

api.php

$con = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8;","$dbuser","$dbpass");

    if(isset($_GET['cat_id'])){
            $result=$con->prepare("SELECT * FROM tbl_news_category c,tbl_news n WHERE c.cid=n.cat_id and c.cid='".$_GET['cat_id']."' ORDER BY n.nid DESC");         
    }
    else if(isset($_GET['latest_news'])){
            $limit=$_GET['latest_news'];
            $result=$con->prepare("SELECT * FROM tbl_news_category c,tbl_news n WHERE c.cid=n.cat_id ORDER BY n.nid DESC LIMIT $limit");            
    }
    else if(isset($_GET['apps_details'])){ 
            $result=$con->prepare("SELECT * FROM tbl_settings WHERE id='1'");       
    }
    else{   
            $result=$con->prepare("SELECT * FROM tbl_news_category ORDER BY cid DESC");         
    }
    $set = array();
    $result->execute();
    $total_records = $result->rowCount();
    if($total_records >= 1){
        while($link=$result->fetch(PDO::FETCH_ASSOC)){
        $set['NewsApp'][] = $link;
      }
    }
     echo $val= str_replace('\\/', '/', json_encode($set)); 
?>

After forcefully terminate android application, website run smoothly. First fall I think it is cache/poor connectivity problem. I changed internet connectivity, cleared cache, used other device, PC, browser. But problem can't solve. If I use two database, it works fine. I don't want to store same content in two database. Actually what caused the problem, hosting server or code ??

  • 写回答

1条回答 默认 最新

  • dqrm8199 2018-01-20 16:24
    关注

    Looks like it's a problem with your code. A query from the Android app locks the tables and your website can't perform queries in those tables. Set a reasonable timeout for your query in the Android app and then check the slow query log to see which query hangs or while the Android app is running the query run the query SHOW FULL PROCESSLIST; to see the problematic query.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line