PHP²Ù×÷mysqlÊý¾Ý¿â¼òµ¥Ê¾Àý
ÏÈ´´½¨Ò»¸öÊý¾Ý¿âMyDB
CREATE DATABASE `mydb` ;
ÔÙ´´½¨Ò»¸ö¼òµ¥µÄÊý¾Ý±í
CREATE TABLE `MyDB`.`MyTable` (
`Name` VARCHAR( 20 ) NOT NULL ,
`Age` INT NOT NULL
) ENGINE = MYISAM
²åÈëһЩÊý¾Ý
INSERT INTO `mydb`.`mytable` (
`Name` ,
`Age`
)
VALUES (
'Jim', '15'
), (
'Amy', '16'
), (
'Jack', '12'
), (
'Mike', '21'
);
н¨Ò»¸öPHPÍøÒ³
<?php
$m_DB = mysql_connect("localhost","root","123"); //Á¬½ÓÊý¾Ý¿â
mysql_select_db("MyDB",$m_DB); //Ñ¡ÔñÒª²Ù×÷µÄÊý¾Ý¿â
$sql = "SELECT * from MyTable"; //¹¹Ôì²éѯÓï¾ä
$re = mysql_query($sql,$m_DB); //Ö´Ðвéѯ
while($row=mysql_fetch_array($re)){ //Ñ»·Êä³öÊý¾Ý
print_r($row); //´òÓ¡³öÀ´
print("<br/>");
}
mysql_close($m_DB);
?>
ÔËÐнá¹ûÈçÏ£º
Array ( [0] => Amy [Name] => Amy [1] => 16 [Age] => 16 )
Array ( [0] => Jim [Name] => Jim [1] => 15 [Age] => 15 )
Array ( [0] => Jack [Name] => Jack [1] => 12 [Age] => 12 )
Array ( [0] => Mike [Name] => Mike [1] => 21 [Age] => 21 )
Ïà¹ØÎĵµ£º
Ò». 1. ǶÈë·½·¨£º »òÕß 2. Ó¦ÓÃÎļþ£º £¨1£©require("MyRequireFile.php")£º·ÅÔÚphp³ÌÐòµÄ×îÇ°Ã棬ÔÚphp³ÌÐòÖ´ÐÐÇ°ÒýÈë £¨2£©include("MyIncludeFile.php")£º·ÅÔÚÁ÷³Ì¿ØÖƵĴ¦Àí²¿·Ö£¬ÔÚÔËÐе½includeʱÔÙ¶ÁÈ¡½øÀ´ 3. ×¢ÊÍ·½·¨£º »ìºÏCºÍ»ã±à£º// £¬/* */£¬ # 4. ±äÁ¿ÀàÐÍ£º £¨1£©PHP±äÁ¿Ò ......
Èç¹ûÄúÉÐδ´òËãÓà OO ÔÔò´´½¨Ó¦ÓóÌÐò£¬ÔòʹÓà PHP µÄÃæÏò¶ÔÏó£¨OO£©µÄÓïÑÔÌØÐÔ£¬Õâ 7 ¸öÏ°¹ß½«°ïÖúÄú¿ªÊ¼ÔÚ¹ý³Ì±à³ÌÓë OO ±à³ÌÖ®¼ä½øÐÐת»»¡£
ÔÚ PHP ±à³ÌÔçÆÚ£¬PHP ´úÂëÔÚ±¾ÖÊÉÏÊÇÏÞÓÚÃæÏò¹ý³ÌµÄ¡£¹ý³Ì´úÂë µÄÌØÕ÷ÔÚÓÚʹÓùý³Ì¹¹½¨Ó¦ÓóÌÐò¿é¡£¹ý³Ìͨ¹ýÔÊÐí¹ý³ÌÖ®¼äµÄµ÷ÓÃÌṩijÖ̶ֳȵÄÖØÓá£
µ«ÊÇ£¬Ã»ÓÐÃæÏò¶ÔÏóµÄÓï ......
¿´µ½²»ÉÙÓû§·´Ó³×ª»»ÍêÒÔºóÊÇÂÒÂëµÄÇé¿ö,³öÏÖÕâÖÖÏÖÏóµÄÖ÷ÒªÔÒòÊÇÕâÀàÓû§Ê¹ÓõĶ¼ÊÇmysql4.1ÒÔÉϵİ汾.ÏÂÃæ×÷Ò»¸ö˵Ã÷,Ï£Íû³öÏÖÕâ¸öÎÊÌâµÄÅóÓѶ¼ÄÜÄÍÐĵİÑÕâ¸öÎĵµ¿´Íê!!!
MySQL 4.1¿ªÊ¼£¬¶Ô¶àÓïÑÔµÄÖ§³ÖÓÐÁ˺ܴó±ä»¯ (Õâµ¼ÖÂÁËÎÊÌâµÄ³öÏÖ)¡£¾¡¹Ü´ó²¿·ÖµÄµØ·½ (°üÀ¨¸öÈËʹÓúÍÖ÷»úÌṩÉÌ)£¬MySQL 3¡¢4.0 ÈÔȻռÖ÷µ¼µØ ......
½ñÌ죬Êý¾Ý¿âµÄ²Ù×÷Ô½À´Ô½³ÉΪÕû¸öÓ¦ÓõÄÐÔÄÜÆ¿¾±ÁË£¬Õâµã¶ÔÓÚWebÓ¦ÓÃÓÈÆäÃ÷ÏÔ¡£¹ØÓÚÊý¾Ý¿âµÄÐÔÄÜ£¬Õâ²¢²»Ö»ÊÇDBA²ÅÐèÒªµ£ÐĵÄÊ£¬¶øÕâ¸üÊÇÎÒÃdzÌÐòÔ±ÐèҪȥ¹Ø×¢µÄÊÂÇé¡£µ±ÎÒÃÇÈ¥Éè¼ÆÊý¾Ý¿â±í½á¹¹£¬¶Ô²Ù×÷Êý¾Ý¿âʱ£¨ÓÈÆäÊDzé±íʱµÄSQLÓï¾ä£©£¬ÎÒÃǶ¼ÐèҪעÒâÊý¾Ý²Ù×÷µÄÐÔÄÜ¡£ÕâÀÎÒÃDz»»á½²¹ý¶àµÄSQLÓï¾äµÄÓÅ»¯£¬¶øÖ»ÊÇÕë ......
tomcat °²×°Ä¿Â¼ÏµÄconfĿ¼ÖеÄcontext.xmlÓëweb.xmlÎļþ·Ö±ðÐÞ¸ÄÈçÏ£º
context.xml мÓÈçÏÂÄÚÈÝ£º
<Resource name="jdbc/mysql"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://Êý¾Ý¿âµØÖ·:3306/Êý¾Ý¿âà ......