PHP MySql增刪改查的簡單實(shí)例
mysql_connect()連接數(shù)據(jù)庫
mysql_select_db選擇數(shù)據(jù)庫
mysql_fetch_assoc()獲取結(jié)果集
mysql_query()執(zhí)行sql語句
實(shí)例如下:
<?php
$con=@mysql_connect('localhost','root','root');//連接數(shù)據(jù)庫
mysql_select_db('test',$con);//選擇數(shù)據(jù)庫
$userInfo=mysql_query("select * from user",$con);//創(chuàng)建sql語句
echo "<table>";
while($row=mysql_fetch_assoc($userInfo))//獲取結(jié)果集每一行的數(shù)據(jù)
{
echo "<tr>";
echo "<td>";
echo $row['id'];//獲取行中的id
echo "</td>";
echo "<td>";
echo $row['username'];
echo "</td>";
echo "<td>";
echo $row['password'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($userInfo);//釋放結(jié)果集
mysql_close($con); //關(guān)閉數(shù)據(jù)庫
/*delete
$d=@mysql_connect('localhost','root','root');
mysql_select_db('test',$d);
mysql_query("delete from user where id=1",$d);
mysql_close($d);
*/
/*insert
$i=@mysql_connect('localhost','root','root');
mysql_select_db('test',$i);
mysql_query("insert into user(username,password) values('ad','ad')",$i);
mysql_close($i);
*/
//update
$u=@mysql_connect('localhost','root','root');
mysql_select_db('test',$u);
mysql_query("update user set username='aaa' where username='00'",$u);
echo "update user set username='ax' where id=2";
mysql_close($u);
?>
以上這篇PHP MySql增刪改查的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
smarty內(nèi)置函數(shù)config_load用法實(shí)例
這篇文章主要介紹了smarty內(nèi)置函數(shù)config_load用法,實(shí)例分析了{(lán)config_load}配置變量的使用技巧,需要的朋友可以參考下2015-01-01
PHP中把stdClass Object轉(zhuǎn)array的幾個方法
PHP和JS通訊通常都用json,但用 json 傳過來的數(shù)組并不是標(biāo)準(zhǔn)的array,而是 stdClass 類型。那么我們可以參考下面的幾個方法進(jìn)行轉(zhuǎn)換。2014-05-05
php與c 實(shí)現(xiàn)按行讀取文件實(shí)例代碼
這篇文章主要介紹了php與c 實(shí)現(xiàn)按行讀取文件實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-01-01
php array_values 返回數(shù)組的值實(shí)例詳解
php array_values 函數(shù)用于返回數(shù)組中所有的值,注意該函數(shù)將為新數(shù)組建立數(shù)組索引,原來的文字索引將不存在。本文章向大家講解array_values函數(shù)的基本語法及使用實(shí)例,需要的朋友可以參考下2016-11-11
php結(jié)合飛信 免費(fèi)天氣預(yù)報短信
最近發(fā)現(xiàn)了一個飛信的API接口,為了好好利用這個資源制作了這個天氣預(yù)報短信通知。2009-05-05

