├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE.txt ├── MySQL-PHP-JSON.iml ├── PHP FILES HERE ├── connection.php ├── insertStudent.php └── showStudents.php ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── practise │ │ └── mysql_php_json │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── practise │ │ └── mysql_php_json │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MySQL-PHP-JSON -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android 39 | 40 | 41 | Android Lint 42 | 43 | 44 | Class structureJava 45 | 46 | 47 | Code maturity issuesJava 48 | 49 | 50 | Gradle 51 | 52 | 53 | Java 54 | 55 | 56 | Java language level migration aidsJava 57 | 58 | 59 | Javadoc issuesJava 60 | 61 | 62 | Performance issuesJava 63 | 64 | 65 | Probable bugsGradle 66 | 67 | 68 | TestNG 69 | 70 | 71 | Threading issuesJava 72 | 73 | 74 | 75 | 76 | Android 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 98 | 99 | 100 | 101 | 102 | Android API 22 Platform 103 | 104 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 miskoajkula 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MySQL-PHP-JSON.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PHP FILES HERE/connection.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PHP FILES HERE/insertStudent.php: -------------------------------------------------------------------------------- 1 | 32 | -------------------------------------------------------------------------------- /PHP FILES HERE/showStudents.php: -------------------------------------------------------------------------------- 1 | 0) { 20 | while ($row = mysqli_fetch_assoc($result)) { 21 | $temp_array[] = $row; 22 | } 23 | } 24 | 25 | header('Content-Type: application/json'); 26 | echo json_encode(array("students"=>$temp_array)); 27 | mysqli_close($connect); 28 | 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ?> -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "practise.mysql_php_json" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:23.0.0' 25 | compile 'com.mcxiaoke.volley:library:1.0.18' 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in X:\ProgramFiles\AndroidSdk\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/practise/mysql_php_json/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package practise.mysql_php_json; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/practise/mysql_php_json/MainActivity.java: -------------------------------------------------------------------------------- 1 | package practise.mysql_php_json; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.EditText; 8 | import android.widget.TextView; 9 | 10 | import com.android.volley.AuthFailureError; 11 | import com.android.volley.Request; 12 | import com.android.volley.RequestQueue; 13 | import com.android.volley.Response; 14 | import com.android.volley.VolleyError; 15 | import com.android.volley.toolbox.JsonObjectRequest; 16 | import com.android.volley.toolbox.StringRequest; 17 | import com.android.volley.toolbox.Volley; 18 | 19 | import org.json.JSONArray; 20 | import org.json.JSONException; 21 | import org.json.JSONObject; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | 27 | public class MainActivity extends AppCompatActivity { 28 | 29 | EditText firstname, lastname, age; 30 | Button insert, show; 31 | RequestQueue requestQueue; 32 | String insertUrl = "http://192.168.1.65/tutorial/insertStudent.php"; 33 | String showUrl = "http://192.168.1.65/tutorial/showStudents.php"; 34 | TextView result; 35 | 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_main); 40 | 41 | firstname = (EditText) findViewById(R.id.editText); 42 | lastname = (EditText) findViewById(R.id.editText2); 43 | age = (EditText) findViewById(R.id.editText3); 44 | insert = (Button) findViewById(R.id.insert); 45 | show = (Button) findViewById(R.id.showstudents); 46 | result = (TextView) findViewById(R.id.textView); 47 | 48 | 49 | requestQueue = Volley.newRequestQueue(getApplicationContext()); 50 | 51 | show.setOnClickListener(new View.OnClickListener() { 52 | 53 | @Override 54 | public void onClick(View view) { 55 | System.out.println("ww"); 56 | JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, 57 | showUrl, new Response.Listener() { 58 | @Override 59 | public void onResponse(JSONObject response) { 60 | System.out.println(response.toString()); 61 | try { 62 | JSONArray students = response.getJSONArray("students"); 63 | for (int i = 0; i < students.length(); i++) { 64 | JSONObject student = students.getJSONObject(i); 65 | 66 | String firstname = student.getString("firstname"); 67 | String lastname = student.getString("lastname"); 68 | String age = student.getString("age"); 69 | 70 | result.append(firstname + " " + lastname + " " + age + " \n"); 71 | } 72 | result.append("===\n"); 73 | 74 | } catch (JSONException e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | } 79 | }, new Response.ErrorListener() { 80 | @Override 81 | public void onErrorResponse(VolleyError error) { 82 | System.out.append(error.getMessage()); 83 | 84 | } 85 | }); 86 | requestQueue.add(jsonObjectRequest); 87 | } 88 | }); 89 | 90 | insert.setOnClickListener(new View.OnClickListener() { 91 | @Override 92 | public void onClick(View view) { 93 | StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener() { 94 | @Override 95 | public void onResponse(String response) { 96 | 97 | System.out.println(response.toString()); 98 | } 99 | }, new Response.ErrorListener() { 100 | @Override 101 | public void onErrorResponse(VolleyError error) { 102 | 103 | } 104 | }) { 105 | 106 | @Override 107 | protected Map getParams() throws AuthFailureError { 108 | Map parameters = new HashMap(); 109 | parameters.put("firstname",firstname.getText().toString()); 110 | parameters.put("lastname",lastname.getText().toString()); 111 | parameters.put("age",age.getText().toString()); 112 | 113 | return parameters; 114 | } 115 | }; 116 | requestQueue.add(request); 117 | } 118 | 119 | }); 120 | 121 | 122 | } 123 | 124 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 22 | 23 | 35 | 36 | 48 | 49 |