標籤:ar os sp 資料 on 代碼 bs as 資料庫
php簡單的串連資料庫的代碼
$host = "192.168.51.18:3306";
$root = "登入名稱稱";
$password = "登入密碼";
$dbname = "資料庫名稱";
$connect = mysql_connect($host,$root,$password,$dbname);
mysql_select_db("erp_database", $connect);//erp_database是庫名
if (!$connect)
{
die(‘Could not connect: ‘ . mysql_error());
}
//這是查詢
$sql="select * from erp_orders where erp_orders_id=‘1054639851‘";
//添加
/$sql=”insert into ………….”;
$result = mysql_query($sql);
print_r(mysql_fetch_row($result));
while($row = mysql_fetch_array($result))
{
echo $row[‘erp_orders_id‘] . " -->" . $row[‘buyer_name‘];
echo "<br />";
}
mysql_connect()函數是串連資料庫
mysql_select_db(‘庫名’,mysql_connect(‘地址 ,‘name’,’password’,’庫名’))
mysql_fetch_array()是將查詢出來的值轉化為數組。當用print_r()列印的時候是有數字和欄位作為鍵,值是一樣的。mysql_fetch_row()和mysql_fetch_array()的區別就是mysql_fetch_row()函數列印出來的鍵是數字沒有欄位作為鍵。
2.mysql_real_escape_string 轉化為字串。
php串連資料庫