Presentation is loading. Please wait.

Presentation is loading. Please wait.

App Inventor2呼叫PHP存取MySQL

Similar presentations


Presentation on theme: "App Inventor2呼叫PHP存取MySQL"— Presentation transcript:

1 App Inventor2呼叫PHP存取MySQL

2 1. MySQL資料庫 Free MySQL Hosting https://www.freemysqlhosting.net/
Log in:輸入 Address及Password 進入資料庫管理介面

3 MySQL資料庫 輸入資料庫管理介面相關資料

4 MySQL資料庫 新增關聯表(mouse) 包含以下三個欄位 -128 ~ 127

5 MySQL資料庫 關聯表(mouse) 插入一筆記錄

6 2. PHP程式 上傳(新增)一筆記錄: update.php <?php
header("Content-Type:text/html; charset=utf-8"); $con = mysqli_connect("sql6.freemysqlhosting.net","sql ","ubURmRvkZI","sql "); // Check connection if (mysqli_connect_errno()) { echo "無法連線到MySQL: " . mysqli_connect_error(); } $user = $_POST['user']; $score = $_POST['score']; $current = $_POST['current']; // Perform queries $sql="INSERT INTO mouse (user, score, current) VALUES (CONVERT(_utf8 '$user' USING utf8), '$score', '$current')"; if (mysqli_query($con,$sql)){ echo "您的資料上傳成功"; else { echo "您的資料上傳失敗"; mysqli_close($con); ?>

7 PHP程式 查詢所有記錄: hero.php <?php
header("Content-Type:text/html; charset=utf-8"); $con = mysqli_connect("sql6.freemysqlhosting.net","sql ","ubURmRvkZI","sql "); // Check connection if (mysqli_connect_errno()) { echo "無法連線到MySQL: " . mysqli_connect_error(); } // Perform queries mysqli_query($con,"SET CHARACTER SET UTF8"); $sql="SELECT * FROM mouse ORDER BY score DESC, current DESC"; $result = mysqli_query($con,$sql); $json = array(); if(mysqli_num_rows($result)){ while($row=mysqli_fetch_assoc($result)){ $json[]=$row; echo urldecode(json_encode($json)); mysqli_close($con); ?>

8 PHP程式 將php程式上傳到網頁空間,並確定網址,例如:

9 3. App Inventor2專案 行動裝置介面設計

10 3.1 讀取目前日期時間

11 修改日期時間顯示格式

12 3.2 利用WEB元件上傳資料

13 WEB元件回傳資料後,提供訊息

14 3.3 查詢英雄榜 畫面載入/上傳成績後,呼叫hero.php更新排名資料

15 查詢英雄榜 利用JsonTextDecode,將回傳資料轉成Json格式

16 查詢英雄榜 處理Json資料(取姓名欄位之值) 每筆第3個欄位的第2個值

17 查詢英雄榜 調整顯示方式實例


Download ppt "App Inventor2呼叫PHP存取MySQL"

Similar presentations


Ads by Google