???????????????????????????????????????????????Web??????????????????????????????????DBA???????????£????????????????????????????顣???????????????????????????????????????????SQL??????????????????????????????????????????????SQL?????????????????MySQL???Web????????????????????Щ?????????????á?
????1.????????????????
???????????MySQL???????????????????檔???????????Ч??????????????????MySQL??????????洦???????к?????????????????ε??????Щ???????????????????У???????????????????????ò????????????????????
????????????????????????????????????????????????????????????????Щ?????????MySQL???????檔????????????
????//??????治????
????$r=mysql_query("SELECT username FROM user WHERE signup_date>=CURDATE()");
????//??????????
????$today=date("Y-m-d");
????$r=mysql_query("SELECT username FROM user WHERE signup_date>='$today'");
????????????SQL????????CURDATE()??MySQL???????????????????????á????????NOW()??RAND()??????????????????SQL?????????????????棬?????Щ????????????????????????????????????????????????????MySQL????????????????檔
????2.EXPLAIN???SELECT???
???????EXPLAIN???????????????MySQL????δ??????SQL????????????????????????????????????????
????EXPLAIN??????????????????????????????????????????????????α????????????……????????
????????????SELECT???????????????????ж????????????????EXPLAIN?????檔????????phpmyadmin???????????????????????????????????У??????????????group_id???????????б??????


???????????group_id??μ?????????

????????????????????????????????7883?У????????????????????????9??16?С???rows?п????????????????????????
????3.???????????????LIMIT 1
???????????????Щ?????????????????????????????????????????fetch?α??????????????鷵?????????
??????????????£?????LIMIT 1??????????????????????MySQL?????????????????????????????????????????????????????????????????
??????????????????????????????“?й?”????????????????????????????Ч???????????????????Select*?????????Select 1??
????//???Ч????
????$r=mysql_query("SELECT*FROM user WHERE country='China'");
????if(mysql_num_rows($r)>0){
????//...
????}
????//??Ч????
????$r=mysql_query("SELECT 1 FROM user WHERE country='China'LIMIT 1");
????if(mysql_num_rows($r)>0){
????//...
????}
????4.???????ν?????
?????????????????????????????Ρ???????????У???????????????????????????????????????佨???????ɡ?

???????????????????????????“last_name LIKE‘a%’”?????????????????????????????????????4???????
??????????????????????????????????????????????????????磬?????????????????????????????????磺“WHERE post_content LIKE‘%apple%’”????????????????????????????????MySQL????????????????????????????????????????????Tag?????
????5.??Join??????????????????????????????
????????????ó????к??JOIN?????????????????????Join?????????????????????????MySQL??????????????Join??SQL????????
???????????Щ??????Join????Σ????????????????????磺????????DECIMAL??κ????INT???Join?????MySQL???????????????????????ЩSTRING?????????????????????????С????????????????п?????????
????//??state?в???company
????$r=mysql_query("SELECT company_name FROM users
????LEFT JOIN companies ON(users.state=companies.state)
????WHERE users.id=$user_id");
????//????state??????????????????????????????????????????????????
????6.????ORDER BY RAND()
??????????????????У???????????????治???????????????÷?????????????????????á??????????????????ж?????μ?????????
????????????????????????д??????????N?????????????????????????????????????????????????????????????????MySQL???ò?????RAND()?????????CPU???????????????????м??????У???????????????????????Limit 1???????£?????????
?????????????????????????
????//????????????
????$r=mysql_query("SELECT username FROM user ORDER BY RAND()LIMIT 1");
????//?????????
????$r=mysql_query("SELECT count(*)FROM user");
????$d=mysql_fetch_row($r);
????$rand=mt_rand(0??$d[0]-1);
????$r=mysql_query("SELECT username FROM user LIMIT$rand??1");
????7.????SELECT*
???????????????????????????????????????????????????????????????WEB??????????????????????????????????????紫???????
?????????????????????????????????????
????//?????
????$r=mysql_query("SELECT*FROM user WHERE user_id=1");
????$d=mysql_fetch_assoc($r);
????echo"Welcome{$d['username']}";
????//???
????$r=mysql_query("SELECT username FROM user WHERE user_id=1");
????$d=mysql_fetch_assoc($r);
????echo"Welcome{$d['username']}";
????8.???????????????ID
????????????????????????????????ID??????????????????????INT??????????UNSIGNED????????????????????AUTO_INCREMENT?????
??????????users?????????????“email”????Σ??????????????????????VARCHAR????????????????????????????????????????У???????????ID????????????????
???????????MySQL?????????£??????Щ????????????????????Щ????£?????????????????÷??????????磬?????????……
?????????????????????????????“??????”??“???”???????????????????????????????????????ɡ????????????????“???”?????磺?????“?????”???????ID???????“?γ??”?пγ?ID???????“?????”??“??????”????????????????γ??????????У????ID??γ?ID??“???”?乲??????????