Konfigurieren Sie einen Xiaoniao-Cloud-Server und stellen Sie eine PHP-Umgebung bereit. Was sind die g?ngigen Methoden zum Herstellen einer Verbindung mit einer MYSQL-Datenbank?
可以參考下
<?php$con = mysql_connect("localhost","root","password");$select_db = mysql_select_db('test');if (!$select_db) {? ? die("could not connect to the db:\n" .? mysql_error());}//查詢代碼$sql = "select * from db_table";$res = mysql_query($sql);if (!$res) {? ? die("could get the res:\n" . mysql_error());}while ($row = mysql_fetch_assoc($res)) {? ? print_r($row);}//查詢代碼//關(guān)閉數(shù)據(jù)庫連接mysql_close($con);?>
其實(shí)用小鳥云服務(wù)器部署PHP環(huán)境,連接MYSQL數(shù)據(jù)庫有幾種常用的辦法,這里就整理了一種最普通的:$mysql_server="localhost";$mysql_username="數(shù)據(jù)庫用戶名";$mysql_password="數(shù)據(jù)庫密碼";$mysql_database="數(shù)據(jù)庫名";//建立數(shù)據(jù)庫鏈接//選擇某個(gè)數(shù)據(jù)庫//執(zhí)行MySQL語句//提取數(shù)據(jù)
云服務(wù)器模擬環(huán)境,和本地沒什么區(qū)別,首先查看是否成功安裝mysql,利用mysqli、或者pdo的方式連接都是可以的。