真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

php封裝數(shù)據(jù)庫(kù)增刪改查,php連接數(shù)據(jù)庫(kù)增刪改查教程

php封裝一個(gè)class類,實(shí)現(xiàn)mysql數(shù)據(jù)庫(kù)的增刪改查怎么操做?

class sqlHelper{ \x0d\x0a public $conn; \x0d\x0a public $dbname="數(shù)據(jù)庫(kù)名稱"; \x0d\x0a public $username="數(shù)據(jù)庫(kù)用戶名"; \x0d\x0a public $password="數(shù)據(jù)庫(kù)密碼"; \x0d\x0a public $host="localhost"; \x0d\x0a //連接數(shù)據(jù)庫(kù) \x0d\x0a public function __construct(){ \x0d\x0a $this-conn=mysql_connect($this-host,$this-username,$this-password); \x0d\x0a if(!$this-conn){ \x0d\x0a die("連接失敗".mysql_error()); \x0d\x0a } \x0d\x0a mysql_select_db($this-dbname,$this-conn); \x0d\x0a } \x0d\x0a //執(zhí)行查詢語(yǔ)句 \x0d\x0a public function execute_dql($sql){ \x0d\x0a $res=mysql_query($sql,$this-conn); \x0d\x0a return $res; \x0d\x0a } \x0d\x0a //執(zhí)行增填改語(yǔ)句 \x0d\x0a public function execute_dml($sql){ \x0d\x0a $b=mysql_query($sql,$this-conn); \x0d\x0a if(!$b){ \x0d\x0a return 3; \x0d\x0a }else{ \x0d\x0a if(mysql_affected_rows($this-conn)){ \x0d\x0a return 1;//表示OK \x0d\x0a }else{ \x0d\x0a return 2;//表示沒(méi)有行收到影響 \x0d\x0a } \x0d\x0a } \x0d\x0a }\x0d\x0a}

綏濱網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),綏濱網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為綏濱近1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的綏濱做網(wǎng)站的公司定做!

如何用PHP代碼實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的增刪改查

?php

$con = mysql_connect("localhost:3306","root","");

if (!$con) {

die('Could not connect: ' . mysql_error());

}

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM user");

echo "table border='1'

tr

thUsername/th

thPassword/th

/tr";

while($row = mysql_fetch_array($result)) {

echo "tr";

echo "td" . $row['username'] . "/td";

echo "td" . $row['password'] . "/td";

echo "/tr";

}

echo "/table";

mysql_close($con);

?

從服務(wù)器中獲取用戶所有信息(SQL SELECT語(yǔ)句)并以表格形式出現(xiàn)

?php

$con = mysql_connect("localhost","root","");

if (!$con) {

die('Could not connect: ' . mysql_error());

}

mysql_select_db("test", $con);

mysql_query("DELETE FROM user WHERE username = '$_POST[username]'");

mysql_close($con);

?

刪除該用戶所有信息delete.php

?php

$con = mysql_connect("localhost:3306","root","");

if (!$con) {

die('Could not connect: ' . mysql_error());

}

mysql_select_db("test", $con);

$sql = "INSERT INTO user (username,password)

VALUES

('$_POST[username]','$_POST[password]')";

if (!mysql_query($sql,$con)) {

die('Error: ' . mysql_error());

}

echo "1 record added";

mysql_close($con);

?

注冊(cè)一個(gè)新用戶insert.php

?php

$con = mysql_connect("localhost","root","");

if (!$con) {

die('Could not connect: ' . mysql_error());

}

mysql_select_db("test", $con);

mysql_query("UPDATE user SET password = '$_POST[password]' WHERE username = '$_POST[username]'");

mysql_close($con);

?

修改一個(gè)用戶密碼update.php

html

head

titleFORM/title

/head

body

br /

h1Insert:/h1

form action="insert.php" method="post"

username:input type="name" name="username"/

br /

password:input type="password" name="password"/

input type="submit" value="submit"/

/form

br /hr /br /

h1Delete/h1

form action="delete.php" method="post"

username:input type="name" name="username" /

br /

Are you sure?input type="submit" value="sure" /

/form

br /hr /br /

h1Update/h1

form action="update.php" method="post"

username:input type="name" name="username"/

br /

You want to change your password into:input type="password" name="password"/

input type="submit" value="submit"/

/form

br /hr /br /

/body

/html

以上三個(gè)功能的提交源Operate.html

php怎么鏈接sqlserver數(shù)據(jù)庫(kù)進(jìn)行增刪改查

php有專門的sql server操作函數(shù),舉個(gè)簡(jiǎn)單的例子,是查詢的

$serverName?=?"localhost";?//數(shù)據(jù)庫(kù)服務(wù)器地址

$uid?=?"root";?//數(shù)據(jù)庫(kù)用戶名

$pwd?=?"123456";?//數(shù)據(jù)庫(kù)密碼

$connectionInfo?=?array("UID"=$uid,?"PWD"=$pwd,?"Database"='databasename');

$conn?=?sqlsrv_connect(?$serverName,?$connectionInfo);

if(?$conn?==?false){

echo?"連接數(shù)據(jù)庫(kù)失敗!";

die(?print_r(?sqlsrv_errors(),?true));

}

$sql?=?"select?*?from?user";

$query?=?sqlsrv_query(?$conn,?$sql?,?array(),?array(?"Scrollable"?=?SQLSRV_CURSOR_KEYSET?));

$num_rows?=?sqlsrv_num_rows($query);

if($num_rows??0){

while?($row?=?sqlsrv_fetch_array($query)){

echo?$row['aaaa'];

}

}

其它的操作也同理,舉一反三


新聞標(biāo)題:php封裝數(shù)據(jù)庫(kù)增刪改查,php連接數(shù)據(jù)庫(kù)增刪改查教程
轉(zhuǎn)載注明:http://weahome.cn/article/hcjoei.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部