簡單php連線資料庫作操作

2022-06-25 04:42:17 字數 1158 閱讀 8361

1、近期穩定版本

<?php

$output = ;

$host = ''; //mysql伺服器位址

$user = ''; //使用者名稱

$pwd = ''; // 密碼

$dbname = '';//資料庫

$connid = mysql_connect($host,$user,$pwd);

//資料庫輸出編碼

mysql_query("set names 'utf8'");

//開啟資料庫

mysql_select_db($dbname,$connid);

//查詢方法

$sql = "";

$query=mysql_query($sql);

//迴圈查詢

while($myrow=mysql_fetch_array($query))

$output = $myrow;

}//輸出

echo json_encode($output);

//關閉連線

mysql_free_result($result);

mysql_close($connid);

?>

2、舊版方便版本

<?php

$output = ;

//需要傳的資料

$openid = $_request['openid'];

//其餘版本

$conn =@mysqli_connect("","root","",""); 

//$conn = mysqli_connect(sae_mysql_host_m, sae_mysql_user, sae_mysql_pass, sae_mysql_db, sae_mysql_port);

$sql = 'set names utf8';

mysqli_query($conn, $sql);

//查詢的方法

$sql = "";

$result = mysqli_query($conn, $sql);

//從結果集中讀取一行記錄

while( true )

$output = $row;

}echo json_encode($output);

?>

php連線資料庫

create table message id tinyint 1 not null auto increment,user varchar 25 not null,title varchar 50 not null,content tinytext not null,lastdate date n...

php連線資料庫

天貓內部優惠券 設定資料庫變數 db host localhost 資料庫主機名稱,一般都為localhost db user root 資料庫使用者帳號,根據個人情況而定 db passw 資料庫使用者密碼,根據個人情況而定 db name test 資料庫具體名稱,以剛才建立的資料庫為準 連線資...

PHP連線資料庫

php連線資料庫函式 mysql connect 開啟mysql連線 mysql select db 開啟乙個資料庫 和or die 隱藏錯誤和條件顯示 mysql connect 主機 使用者名稱 密碼 mysql select db 開啟資料庫 鏈結標示符 如果不是特宣告連線標示符,則預設為是上...