Connect App Inventor to MySQL Database

Connect App Inventor to MySQLIn this tutorial I want to show you how to connect App Inventor to a MySQL database using PHP. I tried to keep everything as simple as possible while at the same time teaching enough so that you can do anything.

You’ll be able to submit to, update and then receive a CSV file from the database using the PHP files below. You’ll also be able to limit access to data simply by creating a different PHP file for each person that would need to access the database. Everything you need can be found below.

If you like videos like this, it helps my search results if you tell Google Plus with a click here

 

MySQL Database Setup 

App Inventor Database

App Inventor MySQL Design View

App Inventor Designview PHP MySQL

App Inventor MySQL Blocks

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

Click the image below a few times to view it full screen

AppInventor22Blocks.png

 

PHP Code that You’ll Upload to a Server

 

01 <?php
02  
03 DEFINE ('DBUSER', 'YourDatabaseUserName');
04 DEFINE ('DBPW', 'YourPassword');
05 DEFINE ('DBHOST', 'YourDatabaseHost');
06 DEFINE ('DBNAME', 'YourDatabaseName');
07   
08 $dbc = mysqli_connect(DBHOST,DBUSER,DBPW);
09 if (!$dbc) {
10     die("Database connection failed: " . mysqli_error($dbc));
11     exit();
12 }
13  
14 $dbs = mysqli_select_db($dbc, DBNAME);
15 if (!$dbs) {
16     die("Database selection failed: " . mysqli_error($dbc));
17     exit();
18 }
19  
20 $result = mysqli_query($dbc, "SHOW COLUMNS FROM customer");
21 $numberOfRows = mysqli_num_rows($result);
22 if ($numberOfRows > 0) {
23  
24 /* By changing Fred below to another specific persons name you can limit access to just the part of the database for that individual. You could eliminate WHERE recorder_id='Fred' all together if you want to give full access to everyone. */
25  
26 $values = mysqli_query($dbc, "SELECT * FROM customer WHERE recorder_id='Fred'");
27 while ($rowr = mysqli_fetch_row($values)) {
28  for ($j=0;$j<$numberOfRows;$j++) {
29   $csv_output .= $rowr[$j].", ";
30  }
31  $csv_output .= "\n";
32 }
33  
34 }
35  
36 print $csv_output;
37 exit;
38 ?>

 

01 <?php
02  
03 DEFINE ('DBUSER', 'YourDatabaseUserName');
04 DEFINE ('DBPW', 'YourPassword');
05 DEFINE ('DBHOST', 'YourDatabaseHost');
06 DEFINE ('DBNAME', 'YourDatabaseName');
07  
08 $dbc = mysqli_connect(DBHOST,DBUSER,DBPW);
09 if (!$dbc) {
10     die("Database connection failed: " . mysqli_error($dbc));
11     exit();
12 }
13  
14 $dbs = mysqli_select_db($dbc, DBNAME);
15 if (!$dbs) {
16     die("Database selection failed: " . mysqli_error($dbc));
17     exit();
18 }
19  
20 $FirstName = mysqli_real_escape_string($dbc, $_GET['FirstName']);
21 $LastName = mysqli_real_escape_string($dbc,$_GET['LastName']);
22 $Street = mysqli_real_escape_string($dbc,$_GET['Street']);
23 $City = mysqli_real_escape_string($dbc,$_GET['City']);
24 $State = mysqli_real_escape_string($dbc,$_GET['State']);
25 $Zip = mysqli_real_escape_string($dbc,$_GET['Zip']);
26 $Email = mysqli_real_escape_string($dbc,$_GET['Email']);
27 $Phone = mysqli_real_escape_string($dbc,$_GET['Phone']);
28 $Recorder = mysqli_real_escape_string($dbc,$_GET['Recorder']);
29  
30 $query = "INSERT INTO customer (first_name, last_name, street_address, city, state, zip_code, email, phone_number, recorder_id) VALUES ('$FirstName', '$LastName', '$Street', '$City', '$State', '$Zip', '$Email', '$Phone', '$Recorder')";
31  
32 $result = mysqli_query($dbc, $query) or trigger_error("Query MySQL Error: " . mysqli_error($dbc));
33  
34 mysqli_close($dbc);
35  
36 ?>

 

01 <?php
02  
03 DEFINE ('DBUSER', 'YourDatabaseUserName');
04 DEFINE ('DBPW', 'YourPassword');
05 DEFINE ('DBHOST', 'YourDatabaseHost');
06 DEFINE ('DBNAME', 'YourDatabaseName');
07  
08 $dbc = mysqli_connect(DBHOST,DBUSER,DBPW);
09 if (!$dbc) {
10     die("Database connection failed: " . mysqli_error($dbc));
11     exit();
12 }
13  
14 $dbs = mysqli_select_db($dbc, DBNAME);
15 if (!$dbs) {
16     die("Database selection failed: " . mysqli_error($dbc));
17     exit();
18 }
19  
20 $FirstName = mysqli_real_escape_string($dbc, $_GET['FirstName']);
21 $LastName = mysqli_real_escape_string($dbc,$_GET['LastName']);
22 $Street = mysqli_real_escape_string($dbc,$_GET['Street']);
23 $City = mysqli_real_escape_string($dbc,$_GET['City']);
24 $State = mysqli_real_escape_string($dbc,$_GET['State']);
25 $Zip = mysqli_real_escape_string($dbc,$_GET['Zip']);
26 $Email = mysqli_real_escape_string($dbc,$_GET['Email']);
27 $Phone = mysqli_real_escape_string($dbc,$_GET['Phone']);
28  
29 $CustomerId = mysqli_real_escape_string($dbc,$_GET['CustomerId']);
30  
31 $query = "UPDATE customer SET first_name='$FirstName', last_name='$LastName', street_address='$Street', city='$City', state='$State', zip_code='$Zip', email='$Email', phone_number='$Phone' WHERE cust_id='$CustomerId'";
32  
33 $result = mysqli_query($dbc, $query) or trigger_error("Query MySQL Error: " . mysqli_error($dbc));
34  
35 mysqli_close($dbc);
36  
37 ?>
38  
39 <!-- http://newjustin.com/updatecust.php?FirstName=Sue&LastName=Banas&Street=123&City=Pittsburgh&State=PA&Zip=15222&Email=derek@aol.com&Phone=4125551212&CustomerId=14
40 -->

 

 
 
 

 

 

[출처] http://www.newthinktank.com/2014/05/connect-app-inventor-mysql-database/

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
101 나인패치(Nine Patch) 이미지란? file 졸리운_곰 2020.10.10 54
100 Python으로 안드로이드 앱 만들기 졸리운_곰 2020.09.30 839
99 [Android] Fragment 를 이용한 탭 만들기 file 졸리운_곰 2020.09.19 52
98 빠르게배우는 안드로이드 Fragment-4(Fragment간 에 데이터전달) file 졸리운_곰 2020.09.19 36
97 빠르게배우는 안드로이드 Fragment-3(Fragment기초 실습) file 졸리운_곰 2020.09.19 58
96 빠르게배우는 안드로이드 Fragment-2(Activity-> Fragment로 쉽게 변경) 졸리운_곰 2020.09.19 38
95 빠르게배우는 안드로이드 Fragment -1 (배경) file 졸리운_곰 2020.09.19 38
94 안드로이드 스튜디오 - 새로 생성한 Activity Class를 쉽게 Manifest에 등록하기. file 졸리운_곰 2020.08.08 52
93 Android Studio Build시 failed linking references 해결방법 file 졸리운_곰 2020.05.05 517
92 [안드로이드 스튜디오] COULD NOT FIND COM.ANDROID.TOOLS.BUILD:GRADLE:3.0.0-BETA6 file 졸리운_곰 2020.05.05 43
91 Android Sync SQLite Database with Server using PHP and MySQL file 졸리운_곰 2019.02.25 7386
90 안드로이드의 MVC, MVP, MVVM 종합 안내서 file 졸리운_곰 2019.01.06 255
89 Getting Started: WebView-based Applications for Web Developers file 졸리운_곰 2018.09.03 264
88 App Inventor - MySQL interface 앱 인벤터 mysql 연결 file 졸리운_곰 2018.04.07 2320
» Connect App Inventor to MySQL Database 앱 인벤터와 mysql 데이터베이스 연결 file 졸리운_곰 2018.04.07 5276
86 Create an API (PHP) 앱 인벤터와 php 통합 file 졸리운_곰 2018.04.07 493
85 Android WebView javascriptInterface 사용하기 file 졸리운_곰 2018.03.26 497
84 Using the WebViewer Control in App Inventor 앱인터에서 웹뷰 컨트롤 사용 file 졸리운_곰 2018.03.24 390
83 WebView Javascript Processor for App Inventor 앱 인벤터 웹뷰 자바스크립트 인터페이스 file 졸리운_곰 2018.03.24 365
82 android webview로 javascript 호출 및 이벤트 받기(연동하기) file 졸리운_곰 2018.03.19 1299
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED