資源描述:
《mysql增刪改查基本語句.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、mysql增、刪、改、查基本語句數(shù)據(jù)庫的鏈接和選擇及編碼$link=mysql_connect("localhost","root",""ordie("數(shù)據(jù)庫連接失敗".mysql_error(;$sel=mysql_select_db("login",$linkordie("數(shù)據(jù)庫選擇失敗".mysql_error(;mysql_query("setnames'utf8'";添加數(shù)據(jù)$link=mysql_connect("localhost","root",""ordie("數(shù)據(jù)庫連接失敗".my
2、sql_error(;$sel=mysql_select_db("login",$linkordie("數(shù)據(jù)庫選擇失敗".mysql_error(;mysql_query("setnames'utf8'",$sel;$add="insertintotitle(title,content,username,timevalues('$title','$content','$username',$time";$query=mysql_query($add;if($query{echo"addsucess";
3、echo"";}elseecho"addfalse";刪除數(shù)據(jù)$link=mysql_connect("localhost","root",""ordie("數(shù)據(jù)庫連接失敗".mysql_error(;$sel=mysql_select_db("login",$linkordie("數(shù)據(jù)庫選擇失敗".mysql_error(;mysql_query("setnames'utf8'";$id=$_GET['id'];$delete="deletefromtitlewhereid='$id'";$quer
4、y=mysql_query($delete;if($query{echo"deletesucess!";echo"";}elseecho"deletefalse";改數(shù)據(jù)$link=mysql_connect("localhost","root",""ordie("數(shù)據(jù)庫連接失敗".mysql_error(;$sel=mysql_select_db("login",$linkordie("數(shù)據(jù)庫選擇失敗".mysql_error(;mysql_query("setnames'utf8'",$sel;$
5、update="updatetitlesettitle='".$title."',content='".$content."'whereid='$id'";$query=mysql_query($update;if($query{echo"resetsucess!";echo"";}elseecho"resetfalse";查數(shù)據(jù)$link=mysql_connect("localhost","root",""ordie("數(shù)據(jù)庫連接失敗".mysql_error(;$sel=mysql_select
6、_db("login",$linkordie("數(shù)據(jù)庫選擇失敗".mysql_error(;mysql_query("setnames'utf8'",$sel;$sql="select*fromtitle";$result=mysql_query($sql;while($rel=mysql_fetch_object($result{?>title;?>reset
7、delete}?>1.select查詢語句和條件語句select查詢字段from表名where條件查詢字段:可以使用通配符*、字段名、字段別
8、名(字段名as..)表名:數(shù)據(jù)庫.表名,表名常用條件:=等于、<>不等于、in(值,值)包含、notin(值,值)不包含、like匹配between在范圍、notbetween不在范圍、<、>條件預(yù)算:and、or、()2.select查詢字段from表名where條件(groupby字段分組)(orderby字段,字段asc/desc排序)(limit初始值,結(jié)束值指針查詢)3.select計(jì)算from表名where條件count(*)統(tǒng)計(jì)函數(shù)max(*)最大值函數(shù)min(*)最小值函數(shù)avg(*)
9、平均值sum(*)累加值函數(shù)4.模糊查詢SELECT*FROMtablewhereusernameLIKE'%$username%';修改表名AlterTABLEtable_nameRENAMETOnew_table_name