Pages

Subscribe:

Ads 468x60px

Labels

2013年5月19日 星期日

Google Maps Android API

詳見



Getting Started

Before you can begin working with the API, you will need to download the API and ensure that you have a Google Maps Android API v2 key. Both the API and the key are freely available.

Overview

Creating a new Android application that uses the Google Maps Android API v2 requires several steps. Many of the steps outlined in this section will only have to be performed once, but some of the information will be a handy reference for future applications. The overall process of adding a map to an Android application is as follows:
  1. Download and configure the Google Play services SDK. The Google Maps Android API is distributed as part of this SDK.
  2. Obtain an API key. To do this, you will need to register a project in the Google APIs Console, and get a signing certificate for your app.
  3. Specify settings in the Application Manifest.
  4. Add a map to a new or existing Android project.
  5. Publish your application!
You may wish to begin by looking at some sample code, which is included with the Google Play services SDK.

Getting the Google Maps Android API v2

The API is distributed as part of the Google Play services SDK, which you can download with the Android SDK Manager. To use the Google Maps Android API v2 in your app, you will first need to install the Google Play services SDK. To learn how to install the package, see the Google Play services documentation.
As a prerequisite, you need to install the Android SDK. To learn how to do this, see Installing the SDK.

The Google Maps API Key

Note: The Google Maps Android API v2 uses a new system of managing keys. Existing keys from a Google Maps Android v1 application, commonly known as MapView, will not work with the v2 API.
To access the Google Maps servers with the Maps API, you have to add a Maps API key to your application. The key is free, you can use it with any of your applications that call the Maps API, and it supports an unlimited number of users. You obtain a Maps API key from the Google APIs Console by providing your application's signing certificate and its package name. Once you have the key, you add it to your application by adding an element to your application's manifest file AndroidManifest.xml.
Understanding the process of registering your application and obtaining a key requires some knowledge of Android's publishing process and requirements. In summary, all Android applications must be signed with a digital certificate for which you hold the private key. Because digital certificates are unique, they provide a simple way of uniquely identifying your app. This makes them useful for tracking your application in systems such as Google Play Store, and for tracking your application's use of resources such as the Google Maps servers.
Note: Refer to the Android Guide Signing Your Applications for more information regarding digital certificates.
Maps API keys are linked to specific certificate/package pairs, rather than to users or applications. You only need one key for each certificate, no matter how many users you have for an application. Applications that use the same certificate can use the same API key. However, the recommended practice is to sign each of your applications with a different certificate and get a different key for each one.
Obtaining a key for your application requires several steps. These steps are outlined here, and described in detail in the following sections.
  1. Retrieve information about your application's certificate.
  2. Register a project in the Google APIs Console and add the Maps API as a service for the project.
  3. Once you have a project set up, you can request one or more keys.
  4. Finally, you can add your key to your application and begin development.

Displaying certificate information

The Maps API key is based on a short form of your application's digital certificate, known as its SHA-1 fingerprint. The fingerprint is a unique text string generated from the commonly-used SHA-1 hashing algorithm. Because the fingerprint is itself unique, Google Maps uses it as a way to identify your application.
To display the SHA-1 fingerprint for your certificate, first ensure that you have the certificate itself. You may have two certificates:
  • Debug certificate: The Android SDK tools generate this certificate automatically when you do a "debug" build from the command line, or when you build and run a project from Eclipse without exporting it as a released application. The certificate is only for use with an application that you're testing; you can't publish an app that's signed with a debug certificate. The debug certificate is described in more detail in the section Signing in Debug Mode in the Android Developer Documentation. You can generate an API key from this certificate, but only use the key for testing, never for production.
  • Release certificate: The Android SDK tools generate this certificate when you do a "release" build with either ant program or Eclipse. You can also generate this certificate using the keytool program. This certificate can be used with an app you release to the world. Once you have the correct certificate for your needs, you can display its SHA-1 fingerprint using the keytool program.
  • For more information about Keytool, see the documentation at http://docs.oracle.com/javase/6/docs/technotes/tools/windows/keytool.html.

Creating an API Project

Once you have your signing certificate fingerprint, create or modify a project for your application in the Google APIs Console and register for the Maps API.
To get a project and register for the API:
  1. In a browser, navigate to the Google APIs Console.
    • If you haven't used the Google APIs Console before, you're prompted to create a project that you use to track your usage of the Google Maps Android API. ClickCreate Project; the Console creates a new project called API Project. On the next page, this name appears in the upper left hand corner. To rename or otherwise manage the project, click on its name.
    • If you're already using the Google APIs Console, you will immediately see a list of your existing projects and the available services. It's still a good idea to use a new project for Google Maps Android API, so select the project name in the upper left hand corner and then click Create.
  2. You should see a list of APIs and services in the main window. If you don't, select Services from the left navigation bar.
  3. In the list of services displayed in the center of the page, scroll down until you see Google Maps Android API v2. To the right of the entry, click the switch indicator so that it is on.
  4. This displays the Google Maps Android API Terms of Service. If you agree to the terms of service, click the checkbox below the terms of service, then click Accept. This returns you to the list of APIs and services.
You're now ready to get a Maps API key.

Obtaining an API Key

If your application is registered with the Google Maps Android API v2 service, then you can request an API key. It's possible to register more than one key per project.
To get the key:
  1. In the left navigation bar, click API Access.
  2. In the resulting page, click Create New Android Key....
  3. In the resulting dialog, enter the SHA-1 fingerprint, then a semicolon, then your application's package name. For example:
    BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75;com.example.android.mapexample
  4. The Google APIs Console responds by displaying Key for Android apps (with certificates) followed by a forty-character API key, for example:
    AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
  5. Copy this key value. You will use it in the next step.

Adding the API Key to your application

The final step is to add the API key to your application. It goes in your application's manifest, contained in the file AndroidManifest.xml. From there, the Maps API reads the key value and passes it to the Google Maps server, which then confirms that you have access to Google Maps data.
To add the key to your application:
  1. In AndroidManifest.xml, add the following element as a child of the  element, by inserting it just before the closing tag 
:

    android:name="com.google.android.maps.v2.API_KEY"
    android:value="your_api_key"/>
substituting your API key for your_api_key. This element sets the key com.google.android.maps.v2.API_KEY to the value your_api_key and makes the API key visible to any MapFragment in your application.
  • Add the following elements to your manifest. Replace com.example.mapdemo with the package name of your application.
    
            android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
     android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
  • Save AndroidManifest.xml and re-build your application.
  • Specify settings in the Application Manifest

    An Android application that uses the Google Maps Android API needs to specify the following settings in its manifest file, AndroidManifest.xml:
    • Permissions that give the application access to Android system features and to the Google Maps servers.
    • Notification that the application requires OpenGL ES version 2. External services can detect this notification and act accordingly. For example, Google Play Store won't display the application on devices that don't have OpenGL ES version 2.
    • The Maps API key for the application. The key confirms that you've registered with the Google Maps service via the Google APIs Console.
    This section describes each of these settings and how to add them to AndroidManifest.xml.

    Specifying permissions

    Set permissions by adding  elements as children of the  element. The syntax is:
     android:name="permission_name"/>
    
    For example, to request the Internet permission, add:
     android:name="android.permission.INTERNET"/>
    
    Besides permissions required by other parts of your application, you must add the following permissions in order to use the Google Maps Android API:
    The following permissions are recommended, but can be ignored if your application does not access the user's current location, either programmatically, or by enabling the My Location layer.
    • android.permission.ACCESS_COARSE_LOCATION Allows the API to use WiFi or mobile cell data (or both) to determine the device's location.
    • android.permission.ACCESS_FINE_LOCATION Allows the API to use the Global Positioning System (GPS) to determine the device's location to within a very small area.
       android:name="android.permission.INTERNET"/>
       android:name="android.permission.ACCESS_NETWORK_STATE"/>
       android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
       android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
      
       android:name="android.permission.ACCESS_COARSE_LOCATION"/>
       android:name="android.permission.ACCESS_FINE_LOCATION"/>
      

    Requiring OpenGL ES version 2

    Because version 2 of the Google Maps Android API requires OpenGL ES version 2, you must add a  element as a child of the  element inAndroidManifest.xml:
    
            android:glEsVersion="0x00020000"
            android:required="true"/>
    
    This notifies external services of the requirement. In particular, it has the effect of preventing Google Play Store from displaying your app on devices that don't support OpenGL ES version 2.

    Add a Map

    After you've added references to the Google Play services SDK, added your key and customized your Android Manifest, you can try adding a map to your application.
    The easiest way to test that your application is configured correctly is to add a simple map. You will have to make changes in two files: main.xml and MainActivity.java. Please note that the code below is only useful for testing your settings in an application targeting Android API 12 or later, This code should not be used in a production application. Examples of how to add more robust code appear throughout this guide and in the sample code.
    1. In main.xml, add the following fragment.
      xml version="1.0" encoding="utf-8"?>
       xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:name="com.google.android.gms.maps.MapFragment"/>
      
    2. In MainActivity.java, add the following code.
      package com.example.mapdemo;
      import android.app.Activity;
      import android.os.Bundle;
      public class MainActivity extends Activity {
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
          }
      }
      
    3. Build and run your application. You should see a map. If you don't see a map, confirm that you've completed all of the steps appearing earlier in this document.

    Android學習_如何開始使用Google Maps Android API v2

    前一陣子想要測試一些Google Map的東西,才發現他默默的在2012年12月3日推出了Google Maps Android API v2(官方資料),而原本申請key與使用的方式變的不太一樣。

    要讓手機正確出現Google map需要下列步驟:
    1. 建立個人的keystore。
    2. 由個人的keystore查詢SHA1碼。
    3. 利用SHA1碼至Google apis網站申請key。
    4. 於eclipse安裝Google Play services。
    5. 於要使用Google Map的專案加入google-play-services_lib的Library。
    6. 於專案的AndroidManifest與layout.mal加入需要的設定。
    7. 利用第一步驟的keystore匯出專案為apk檔案。
    8. 以adb安裝上述apk檔案。


    詳細步驟:
    1. 建立個人的keystore。
    A. 開啟DOS命令視窗,找到java的bin資料夾(C:\Program Files\Java\jre6\bin)
    B. 輸入keytool指令(keytool -genkey -v -keystore yourkeyname.keystore -alias yourkeyname -keyalg RSA -keysize 2048 -validity 10000)
    輸入後,會有一系列的問題,需要注意的是過程中會輸入兩種密碼,網路上書上都推薦怕記不住就用一樣。


    2. 由個人的keystore查詢SHA1碼。
    A. 還是一樣先開啟DOS命令視窗,找到java的bin資料夾(C:\Program Files\Java\jre6\bin)
    B. 使用"既有keystore取得SHA1的語法(keytool -list -v -keystore "C:\Program Files\Java\jre6\bin\yourkeyname.keystore"),鍵入語法後就必須要輸入剛剛建立時所設定的密碼。(語法中加上-v才會顯示SHA1碼)


    3. 利用SHA1碼至Google apis網站申請key。
    A. 連至申請網站https://code.google.com/apis/console/ 
    B. 若是第一次使用按Create Project。
    C. 選擇左邊列表的Services,並且將google Maps Android API v2調整成"on"。
    D. 選擇左邊列表的API Access,並且點擊右下角的Create new Android key。
    E. 輸入步驟二得到的SHA1與專案的Package名稱(中間以分號分隔),例:SHA1碼;tw.com.maptest。
    F. 記住API key。


    4. 於eclipse安裝Google Play services。
    A. 進入Android SDK Mnanger(eclipse→windows→Android SDK Mnanger)。
    B. 安裝Extras的Google Play services。


    5. 於要使用Google Map的專案加入google-play-services_lib的Library。
    A. 於eclipse→File→import,選擇Android下的Existing Android Code Into Workspace。
    B. 由Browse選擇→[android-sdk-folder]/extras/google/google_play_services/libproject/google-play-services_lib
    C. 於要使用Google Map的專案按右鍵,選擇Properties。於左側選單選擇Android,並於下方Library上述加入的專案google-play-services_lib。


    6. 於專案的AndroidManifest與layout.xml加入需要的設定。
    A. 打開AndroidManifest加入必須的設定。
    於application標籤之上(注意下述程式碼必須置換yourpackagename成你的package名稱):

    於application標籤中加入(注意下述程式碼必須置換GoogleMapAPIKey成剛剛申請到的Key):

    於application標籤下加入:

    B. 打開layout.xml,將介面先改為較單純的內容,待測試OK後再更改為自己需要的介面。

    C. java用最單純的內容先進行測試: package yourpackageName; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }

    7. 利用第一步驟的keystore匯出專案為apk檔案。
    A. 專案右鍵選擇Android Tools→Export Signed Application Package。
    B. 依照步驟可以匯出帶有簽章的apk檔案(過程中必須輸入最初設定的keystore密碼)


    8. 以adb安裝上述apk檔案。
    A. 利用adb指令(adb install Name.apk)

    最後,執行程式,確認手機有連上網路,迎接你的地圖吧。

    這篇有幫助到你了話,請留"YA~~~看到圖了" 


    2013年3月22日由劉佺網友補充如何在不匯出專案的情況下,使用debug.keystore來進行實機測試:
    以下為完整留言,感謝他的補充: 
    不過隨即發現不用匯出成apk這麼麻煩,如果用他預設的debug.keystore去產生api key,就可以直接從eclipse/Run As去選擇自己的裝置
    預設的debug.keystore可以從Preferences \ Android \ Build \ Default debug keystore去查詢
    步驟二的語法就會變成:keytool -list -v -keystore "C:\Users\使用者名稱\.android\debug.keystore"
    預設的debug.keystore的預設密碼是:android;這樣去申請,DEBUG時測試起來就會比較快(非常多 XD),就不用每次都匯出成專案了

    剛才測試的時候發現,申請完以後,如果要改成自己之前新建的keystore
    1. 先查自定密碼的keystore的SHA1碼
    2. 到Google的API Access分頁
    3. 選擇右邊的Edit allowed Android apps...
    4. 將前半的SHA1碼改掉,分號後面的專案名稱不動
    結果API key也不會變動,匯出專案時就可以用自訂的密碼了
    實際安裝起來Google Map也可以正常顯示
    ----------------------------------------------------------------

    資料來源

    簡易Google地圖教學(Google Maps JavaScript API V3)

    從Google的官方網站中已知Version 3的版本在下載速度上已比Version 2快很多,尤其在Android平台的行動裝置上更能展現其效能,對開發者來說最高興的莫非是此版本已不需要申請API keys,這件事情實在對開發者來說比速度快個零點幾秒鐘來說還令人 感到興奮,開發當中任何可以簡單的事情都是王道,所以在此文章我們也分享我們用來用去最常用的使用Google地圖的做法,雖然簡單,但是真的是在一般案子中可以一用再用。

    我們所要做的就是從db裡loop出來一堆地址,再從地址旁點選小圖來展開google地圖,首先我們先來說如何loading新的Google Maps JavaScript API:

     

    V3變的很簡單,只須簡單的使用上方Javascript的src指向http://maps.google.com/maps/api/js 即可,但後方參數sensor為必要的,當sensor=true時指你要使用sensor來定位(如GPS裝置),因為我們的例子只是用於網頁程式,所以我們將sensor設為false, 現在我們用ASP.NET簡易的從db中叫出要使用地圖的地址(可點選地圖試試):

    高雄縣鳳山市光復路二段132號
    台北市和平東路三段5號
    東京都豊島区東池袋3-1-5


    上方我們用ASP.NET GridView來從db把地址抓出來,最重要的是我們在產生"地圖"的小icon時把連結的link後方帶入地址的參數,用另開視窗的方式來打開地圖,我們link的語法如下:,address 後方帶的地址看起來像亂碼,其實是為了確保中文地址可以在URL上正確的傳遞,我們在傳遞時使用Server.UrlEncode的方法來Encode我們的地址(Server.UrlEncode的使用方法及說明請參閱http://msdn.microsoft.com/en-us/library/axc6fkkb.aspx),我們map.aspx程式如下:





    Google Maps JavaScript API v3 Example: Geocoding Simple










    我們首先看以上範例,最重要就是剛開始有提到的loading API的之後我們來看我們主要的JAVASCRIPT程式,在主要的script內有宣告兩個物件變數:geocoder及map,之後 我們在function initialize()中來產生他們的instance,geocoder = new google.maps.Geocoder();就是我們去new一個geocoder instance的方法,geocoder主要的目的主要是去將實體的地址轉變成google map能定位的經緯度,至於產生新的map instance方式就為map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 在construct google.maps.Map時須帶2個參數,第一就是在網頁地圖上要顯示的div id的名稱,目的就是要google.maps.Map知道顯示在哪裡,第二就是帶入要google.maps.Map產生的起始型態,如zoom的大小或是地圖要產生的形態,initializ function只是初始化geocoder物件,最後再codeAddress()中用Request.QueryString["address"]將地址接收傳至geocoder的geocode中, 目前這種方法最大的好處是可以直接將地址轉換成地圖,而不須用經緯度的方式,但Google會限制其使用的次數。
    資料來源

    在Andorid程式中加入Google MAp


    使用Google Map Api V2,v3(V1已失效)
    V2:將Map內嵌入Android程式,並可做後台管理

    V3:使用Android WebView元件,直接套用網頁作(JS)


    做法: V2
    a.開發環境加入Google Map API 程式庫
    b.申請V2金鑰
    c.撰寫Android Google Map程式   1.加入權限 2.嵌入地圖 3.呼叫API


    V3
    a.引用Google Map API javascript庫
    b.建立嵌入地圖之div
    c.呼叫API

    2013年5月18日 星期六

    How to connect Android with PHP, MySQL

    We are going see how to make a very simple Android app (in our case, a product inventory app) that will call a PHP script to perform basic CRUD(Create, Read, Update, Delete) operations. To brief you on the architecture, this is how it works. First your android app calls a PHP script in order to perform a data operation, lets say “create”. The PHP script then connects to your MySQL database to perform the operation.
    So the data flows from your Android app to PHP script then finally is stored in your MySQL database. Allright, lets dig deeper.


    詳件資料

    Android通过PHP连接MySQL(读取)


    1. 通过 MySQL在windows下的配置 中介绍第二种方法,在服务器机器上配置php和mysql环境,譬如我的服务器机器ip为:10.141.249.136

    2. 新建在test数据库下新建一个teacher表,表的内容如下:

    Android通过PHP连接MySQL(读取)

    3. 在服务器机器上的phpnow安装目录E:\PHPnow-1.5.5\htdocs下新建一个test.php文件,文件内容如下:

    $link=mysql_connect("127.0.0.1","root","123456");
    mysql_query("SET NAMES utf8");
    mysql_select_db("test",$link);
    $sql=mysql_query("select * from teacher ",$link);
    while($row=mysql_fetch_assoc($sql))
    $output[]=$row;
    print(json_encode($output));
    mysql_close();
    ?>

    4. 新建一个Android Java Project
    需要修改的是一下三个文件:AndroidTestActivity.java、main.xml、AndroidManifest.xml
    //AndroidTestActivity.java
    package com.knight.android.test;//根据实际的工程需要,修改包的名称

    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;

    import android.app.Activity;
    import android.net.ParseException;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    public class AndroidTestActivity extends Activity {
    JSONArray jArray;
    String result = null;
    InputStream is = null;
    StringBuilder sb=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         Button b1 = (Button) findViewById(R.id.button1);
         b1.setOnClickListener(new Button.OnClickListener() {
         @Override
         public void onClick(View v) {
         // TODO Auto-generated method stub
         EditText tv = (EditText) findViewById(R.id.editView);
         ArrayList nameValuePairs = new ArrayList();
         //http get
         try{
              HttpClient httpclient = new DefaultHttpClient();
              HttpGet httpget = new HttpGet("http://10.141.249.136/test.php");
              HttpResponse response = httpclient.execute(httpget);
              HttpEntity entity = response.getEntity();
              is = entity.getContent();
         }catch(Exception e){
              Log.e("log_tag", "Error in http connection"+e.toString());
         }
         //convert response to string
         try{
              BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
              sb = new StringBuilder();
              sb.append(reader.readLine() + "\n");
     
              String line="0";
              while ((line = reader.readLine()) != null) {
                   sb.append(line + "\n");
              }
              is.close();
              result=sb.toString();
         }catch(Exception e){
              Log.e("log_tag", "Error converting result "+e.toString());
         }
         //paring data
         int ct_id;
         String ct_name;
         try{
              jArray = new JSONArray(result);
              JSONObject json_data=null;
              for(int i=0;i
                   json_data = jArray.getJSONObject(i);
                   ct_id=json_data.getInt("id");
                   ct_name=json_data.getString("name");
                   tv.append(ct_name+" \n");
              }
         }catch(JSONException e1){
              //   Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
         } catch (ParseException e1) {
              e1.printStackTrace();
         }
    }
    });
    }
    }

    layout/main.xml
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        

    AndroidManifest.xml
        package="com.knight.android.test"
        android:versionCode="1"
        android:versionName="1.0" >
        
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            
                android:name=".AndroidTestActivity"
                android:label="@string/app_name" >
                
                    

                    
                
            
        
        
        


    5. 运行结果如下图:
    Android通过PHP连接MySQL(读取)

    点击click以后,Android会向服务器发送一个Http Get请求,服务器从mysql中读取数据后,传送给Android客户端,客户端编码数据包,然后返回如下结果:

    Android通过PHP连接MySQL(读取)

    注意:
    (1)AndroidManifest.xml中不能出现这种属性,否则Android客户端无法连接到远程服务器
    (2)如果在本机搭建mysql和php环境,以上程序(AndroidTestActivity.java)中红色部分应更改为:
    HttpGet httpget = new HttpGet("http://10.0.2.2/test.php");
        127.0.0.1表示手机的本机ip,因为程序最终是在手机上跑的
    (3)如果读者自定义的工程,需要修改一下几个地方:
    • 第一个是 AndroidTestActivity.java 程序里面的package名称package com.knight.android.test;这个根据读者自己定义的包要做出相应的修改(绿色部分)
    • 第二个是修改 AndroidManifest.xml里面第三行的package=" com.knight.android.test",要保持绿色部分和第一条中的绿色部分相对应
    • 第三点是修改AndroidManifest.xml里面activity下面的 android:name=". AndroidTestActivity",将绿色部分修改为 AndroidTestActivity.java的红色部分(也就是类名)
    (4)在MySQL中把编码设置成utf8_unicode_ci,在浏览器中输入:localhost/test.php,如果中文出现乱码,可以把输出的内容复制到http://tools.jb51.net/tools/json/json_editor.htm,如果在这里能显示正常,则说明实际上是的对的,因为浏览器输出的是json编码
    (5)更多内容还可以参考: http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/ ,这个网站中部分内容是错的,择其善者而从之