先select查詢,返回的結(jié)果顯示到表單中。 在update操作,將在表單中修改的結(jié)果更新到數(shù)據(jù)庫(kù)中。 很容易的,用thinkphp做更容易。
創(chuàng)新互聯(lián)是一家專業(yè)提供中原企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為中原眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(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'];
}
}
其它的操作也同理,舉一反三
?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