?php
在庫車等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站制作,庫車網(wǎng)站建設(shè)費(fèi)用合理。
$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語句)并以表格形式出現(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
class sqlHelper{ \x0d\x0a public $conn; \x0d\x0a public $dbname="數(shù)據(jù)庫名稱"; \x0d\x0a public $username="數(shù)據(jù)庫用戶名"; \x0d\x0a public $password="數(shù)據(jù)庫密碼"; \x0d\x0a public $host="localhost"; \x0d\x0a //連接數(shù)據(jù)庫 \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í)行查詢語句 \x0d\x0a public function execute_dql($sql){ \x0d\x0a $res=mysql_query($sql,$this-conn); \x0d\x0a return $res; \x0d\x0a } \x0d\x0a //執(zhí)行增填改語句 \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;//表示沒有行收到影響 \x0d\x0a } \x0d\x0a } \x0d\x0a }\x0d\x0a}
php有專門的sql server操作函數(shù),舉個(gè)簡單的例子,是查詢的
$serverName?=?"localhost";?//數(shù)據(jù)庫服務(wù)器地址
$uid?=?"root";?//數(shù)據(jù)庫用戶名
$pwd?=?"123456";?//數(shù)據(jù)庫密碼
$connectionInfo?=?array("UID"=$uid,?"PWD"=$pwd,?"Database"='databasename');
$conn?=?sqlsrv_connect(?$serverName,?$connectionInfo);
if(?$conn?==?false){
echo?"連接數(shù)據(jù)庫失敗!";
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'];
}
}
其它的操作也同理,舉一反三
resourse
odbc_connect(
string
dsn,
string
user,
string
password
[,
int
cursor_type])
dsn:系統(tǒng)dsn名稱
user:數(shù)據(jù)庫服務(wù)器某用戶名。
password:數(shù)據(jù)庫服務(wù)器某用戶密碼。
php程序員站
cursor_type:游標(biāo)類型。
這樣連接上access的數(shù)據(jù)庫
增刪改查就是標(biāo)準(zhǔn)的sql語句了,樓主應(yīng)該沒什么問題了吧
本文名稱:php增刪改查連接數(shù)據(jù)庫 php增刪改查mysql實(shí)例
網(wǎng)頁地址:http://jinyejixie.com/article2/dodddoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、Google、網(wǎng)站設(shè)計(jì)、面包屑導(dǎo)航、關(guān)鍵詞優(yōu)化、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)