¼ÈÈ»ÏÖÔÚÄa¿´µ½ÁËÕaƪÎÄÕ£¬ËµÃ÷Äa¿Ï¶¨ÖªµÀPHPºÍMySQLÊÇÔoôһ»ØÊ£¬ÎҾͲ»†ªaÂÁË¡£µ«ÎªÊ²Ã´Äa»¹Òª¼ÌÐøÔĶÁ´ËÎÄÄØ£¿¿ÉÄÜÊÇÒÔÇ°ÄaÏ°¹ß¸´ÖÆÕ³ÌuÒ»Ð(C)´uÂe£¬²¢Ã»ÓÐÕaeÕýŪ¶®´uÂeµÄº¬Òa£»Ò²¿ÉÄÜÄaÒÔǰŪ¶®ÁË£¬µ«ÏñÎÒÒ»Ñu£¬ÓÐÒ»¶Îʱ¼aûÓнӴ¥£¬ÉuÊeÁË£»ÔÙ»oÕߣ¬ÓÐÈËÎÊÄaÀaËƵļoµ¥ÎÊÌa£¬¶øÄaÒѾ²»Ð¼Óڻشð£¬Ö±½ÓÉÏÍøËÑË÷£¬Ç¡ºÃÕÒµ½ÁËÕaƪ£¬ÓÚÊǾÍÍƼo¸øÄÇËËËÁË...
²»¹ÜÔoÑu£¬ÔÚÕaÀiÎÒ×ܽaÁ˳£ÓõÄPHPÁ¬½ÓMySQLÊý¾Ý¿aÒÔ¼°¶ÁȡдÈeÊý¾Ý¿aµÄ½¨£¬Ï£ÍuÄܹ»°iµ½Äa£¬µ±È»Ò²ÊÇ×÷ΪÎÒ×Ô¼ºµÄÒ»¸o»Ø¹Ë×ܽa¡£
1.ΪÁ˸uºÃµØÉeÖÃÊý¾ÝÁ¬½Ó,Ò»°a»a½«Êý¾ÝÁ¬½ÓËuÉae¼°µÄÖµ¶¨Òa³É±aÁ¿.
$mysql_server_name='localhost'; //¸Ä³É×Ô¼ºµÄmysqlÊý¾Ý¿a*þÎñÆ÷
$mysql_username='root'; //¸Ä³É×Ô¼ºµÄmysqlÊý¾Ý¿aÓû§Ãu
$mysql_password='123456'; //¸Ä³É×Ô¼ºµÄmysqlÊý¾Ý¿aÃÜÂe
$mysql_database='Mydb'; //¸Ä³É×Ô¼ºµÄmysqlÊý¾Ý¿aÃu
Ò²¿É°ÑÒÔÉϱaÁ¿*ÅÔÚÒ»¸oÎļþÀi,¿ÉÒÔËaeʱÈÃÆaËuÎļþµ÷ÓÃ.
ÀýÈç: ½«ÒÔÉÏÄÚÈÝ*ÅÔÚ:db_config.php ÄÇôÔÚÆaËuÐeÒªÓõ½Êý¾Ý¿aµÄÒ³ÃaeÖ±½Óµ÷ÓÃ.
µ÷ÓôuÂe:require("db_config.php");
¡¡ 2.Á¬½ÓÊý¾Ý¿a
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password) or die("error connecting") ; //Á¬½ÓÊý¾Ý¿a
mysql_query("set names 'utf8'"); //Êý¾Ý¿aÊa³o±aÂe Ó¦¸ÃÓeÄaµÄÊý¾Ý¿a±aÂe±£³ÖÒ»ÖÂ.ÄϲýÍøÕ¾½¨Ée¹«Ë¾°ÙºaÍøÂçPHP¹¤³Ìʦ½¨ÒeÓÃUTF-8 ¹u¼Ê±e×¼±aÂe.
mysql_select_db($mysql_database); //´o¿ªÊý¾Ý¿a
$sql ="select * from news "; //SQLÓi¾a
$result = mysql_query($sql,$conn); //²eѯ
¡¡¡¡ 3.¶ÁÈ¡±iÖеÄÄÚÈÝ,ÕaÀiÎÒÃÇÓÃwhile,¿ÉÒÔ¸u¾Ý¾ßÌaÇe¿o,ÓÃfor »oÆaËuµÄ.
while($row = mysql_fetch_array($result))
{
echo "<div style=\"height:24px; line-height:24px; font-weight:bold;\">"; //ÅÅ°ae´uÂe
echo $row['Topic'] . "<br/>";
echo "</div>"; //ÅÅ°ae´uÂe
}
¡¡¡¡ 4.phpдÈeÊý¾Ý¿a,MysqlÊý¾ÝµÄдÈe
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password); //Á¬½ÓÊý¾Ý¿a
mysql_query("set names 'utf8'"); //Êý¾Ý¿aÊa³o±aÂe
mysql_select_db($mysql_database); //´o¿ªÊý¾Ý¿a
$sql = "insert into messageboard (Topic,Content,Enabled,Date) values ('$Topic','$Content','1','2011-01-12')";
mysql_query($sql);
mysql_close(); //¹Ø±ÕMySQLÁ¬½Ó