php連接mysql資料庫代碼「php操作mysql資料庫函數」

有啥別有病,沒啥別沒錢,畢業這些年,我卻掏不出給自己治病的錢。。。

—- 網易雲熱評

1、連接資料庫

$lj=mysql_connect("127.0.0.1",'root','root');

2、判斷是否連接成功,連接失敗返回false

var_dump($lj);
從PHP開始學滲透 -- MySQL資料庫操作

3、資料庫操作,增添改查

<?php
$lj=mysql_connect("127.0.0.1",'root','root');//連接資料庫
var_dump($lj);
echo "<br/>";
mysql_query("use aiyou");//選擇要操作的資料庫名稱
mysql_query("insert into bucuo value(4,'1233','456')");//增
mysql_query("delete from bucuo where id=4");//刪
mysql_query("update bucuo set name='333' where id=3");//改
$cxsj=mysql_query("select * from bucuo where id>2");//查
/*$xscxsj=mysql_fetch_array($cxsj);
var_dump($xscxsj);
echo "<br/>";*/
$xscxsj=mysql_fetch_assoc($cxsj);
var_dump($xscxsj);
echo "<br/>";
foreach ($xscxsj as $key => $value) {
    echo "$value"."<br/>";
}
?>
運行結果:
resource(3) of type (mysql link)
array(3) { ["Id"]=> string(1) "3" ["name"]=> string(3) "333" ["pass"]=> string(3) "456" }
3
333
456

禁止非法,後果自負

從PHP開始學滲透 -- MySQL資料庫操作

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/234914.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-12 11:50
下一篇 2024-12-12 11:50

相關推薦

發表回復

登錄後才能評論