skip to Main Content

I want to connect my android application to my phpmyadmin sql database please anyone give me a simple code to do that

2

Answers


  1. There is no particular way, but you can always query the data and then send the data back to the client (android app) as json. Here is an example

        <?php
    require "connect.php";
    
    $searchQuery = $_GET['query'];
    
    $query = "SELECT FPSID, FPSName, DistrictName, SubDistrictName from fpsids WHERE FPSName LIKE '%$searchQuery%'";
    $result = mysqli_query($sqlConnection, $query);
    
    echo "[n";
    if ($result) {
      $trows = mysqli_num_rows($result);
      if ($trows > 0) {
        for($i=0;$i<$trows;$i++) {
           $row = $result->fetch_assoc();
          if ($i < $trows-1) {
           echo json_encode($row) . ",n";
          } else {  
           echo json_encode($row) . "n";
          }
          
        }
        echo "]";
        
      } 
    }
    

    I am getting some records from the sql database then i use json_encode() to make a json from the query results. As I a more than one records returned from the database we can use loops to make complex json.
    Then on the android side you can call your host and query for the search like https://yourhost.com?query=somequery

    This call will return the data to your android app as json, from onwards you can use some json library to display or process the data (Like build-in JsonArray or JsonObject).

    Or

    You can use Google Firebase (FireStore) which is a lot more easier with better documentation.

    Login or Signup to reply.
  2. Phpmyadmin is a PHP driven browser based client admin app to manage MySQL data, it is not the database engine. Therefore, you would not connect your app to phpmyadmin. Rather you would either expose your MySQL database through some form of REST API (probably using PHP) or depending on your app development environment use a MySql database driver to make a direct connection to the database and engine. The REST API is probably more flexible and scalable. Here is a helpful tutorial explaining basic CRUD using a REST API:

    https://webdamn.com/create-simple-rest-api-with-php-mysql/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search