Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:52:29+00:00 2026-05-23T12:52:29+00:00

I have MySQL database server I need to update and retrieve data to/from MySQL

  • 0
  1. I have MySQL database server
  2. I need to update and retrieve data to/from MySQL server via JSON

So, I want to know how to do that, and I pretty confuse with this example statement:

HttpPost httppost = new HttpPost("http://10.0.2.2/city.php");

This means I need to code my application that connect with PHP server
before write php to connect to DB right ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:52:30+00:00Added an answer on May 23, 2026 at 12:52 pm

    To send data to server you could do this:

    private void sendData(ArrayList<NameValuePair> data)
    {
         // 1) Connect via HTTP. 2) Encode data. 3) Send data.
        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new      
            HttpPost("http://www.blah.com/AddAccelerationData.php");
            httppost.setEntity(new UrlEncodedFormEntity(data));
            HttpResponse response = httpclient.execute(httppost);
            Log.i("postData", response.getStatusLine().toString());
                //Could do something better with response.
        }
        catch(Exception e)
        {
            Log.e("log_tag", "Error:  "+e.toString());
        }  
    }
    

    then to send lets say:

    private void sendAccelerationData(String userIDArg, String dateArg, String timeArg,
            String timeStamp, String accelX, String accelY, String accelZ)
    {
        fileName = "AddAccelerationData.php";
    
        //Add data to be send.
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
        nameValuePairs.add(new BasicNameValuePair("userID", userIDArg));
        nameValuePairs.add(new BasicNameValuePair("date",dateArg));
        nameValuePairs.add(new BasicNameValuePair("time",timeArg));
        nameValuePairs.add(new BasicNameValuePair("timeStamp",timeStamp));
    
        nameValuePairs.add(new BasicNameValuePair("accelX",accelX));
        nameValuePairs.add(new BasicNameValuePair("accelY",accelY));
        nameValuePairs.add(new BasicNameValuePair("accelZ",accelZ));
    
        this.sendData(nameValuePairs);
    }
    

    so then the AddAccelerationData.php file on server is:

    <?php
    /*
     * What this file does is it:
     * 1) Creates connection to database.
     * 2) Retrieve the data being send.
     * 3) Add the retrieved data to database 'Data'.
     * 4) Close database connection.
     */
    require_once '../Connection.php'; //connect to a database/disconnect handler.
    require_once '../SendAPI.php'; //deals with sending querys.
    
    $server = new Connection();
    $send = new Send();
    
    //Connect to database.
    $server->connectDB();
    
    //Retrieve the data.
    $userID = $_POST['userID'];
    $date = $_POST['date'];
    $time = $_POST['time'];
    
    $accelX = $_POST['accelX'];
    $accelY = $_POST['accelY'];
    $accelZ = $_POST['accelZ'];
    
    //Add data to database 'Data'. //Personal method to query and add to database.
    $send->sendAccelerationData($userID, $date, $time, $timeStamp, $accelX, $accelY, $accelZ);
    
    
    //Disconnect from database.
    $server->disconnectDB();
    ?>
    

    This is an example I used recently. Just to note in the php file. I import Connection.php
    this just deals with the connection to the database. So just replace that with your code for connecting to MYSQL db. Also I imported SendAPI.php (which you can just ignore)This was just my class for sending data. Basically it contained some of the querys I wanted to use. Such as sendAccelerationData(). Basically class was similar to that of stored procedures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly small MySQL database (a Textpattern install) on a server that
I have a MySQL database of keywords that are presently mixed-case. However, I want
I have a MySQL database that I want to archive . What is the
I have a MySQL database on a web server and need to read the
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
I have a MySQL database behind a firewall which can only be accessed via
Assume that you have a running SQL Server Express instance named (local)\SQLEXPRESS. Its database
I need to connect to a remote MySQL database and have created the following
I have a big SQL Server database I want to connect to and my
I have a MySQL server with many databases that have a similar table structure.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.