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 )
Ïà¹ØÎĵµ£º
<?php
/**
+++++++++++++++++++++=+++++ÉÏ´«Í¼Æ¬++++++++++++++++++++++++++++++++++++++++
—————————————————————————————&mdas ......
¿´µ½²»ÉÙÓû§·´Ó³×ª»»ÍêÒÔºóÊÇÂÒÂëµÄÇé¿ö,³öÏÖÕâÖÖÏÖÏóµÄÖ÷ÒªÔÒòÊÇÕâÀàÓû§Ê¹ÓõĶ¼ÊÇmysql4.1ÒÔÉϵİ汾.ÏÂÃæ×÷Ò»¸ö˵Ã÷,Ï£Íû³öÏÖÕâ¸öÎÊÌâµÄÅóÓѶ¼ÄÜÄÍÐĵİÑÕâ¸öÎĵµ¿´Íê!!!
MySQL 4.1¿ªÊ¼£¬¶Ô¶àÓïÑÔµÄÖ§³ÖÓÐÁ˺ܴó±ä»¯ (Õâµ¼ÖÂÁËÎÊÌâµÄ³öÏÖ)¡£¾¡¹Ü´ó²¿·ÖµÄµØ·½ (°üÀ¨¸öÈËʹÓúÍÖ÷»úÌṩÉÌ)£¬MySQL 3¡¢4.0 ÈÔȻռÖ÷µ¼µØ ......
ÎÒÔÚmysql ÃüÁîÐÐÕâ¸öϵÁÐÀï½éÉܹýÓÐÌõ¼þ²éѯ£¬ËüÓõ½WHERE×Ӿ䡣µ«ÊÇÓÐʱºòÓÃWHERE×Ó¾äÎÞ·¨¸øÎÒÃǵIJéѯ¼ÓÈëÌõ¼þ£¬±ÈÈçÔÚÉÏÒ»½ÚÎÒÃÇѧϰµÄGROUP BY(°´×é¹éÀà)×Ӿ䣬Èç¹ûÎÒÃÇÒªÔÚ°´×é¹éÀàºó¼ÓÈëÌõ¼þ£¬ÓÃWHERE¾ÍÐв»Í¨£¬ÒòΪWHEREÖ»¿ÉÒÔÔÚ°´×é¹éÀàÇ°¼ÓÈëÌõ¼þ¡£ºÃÔÚmysqlÌṩHAVING×Ӿ䣬Ëü¿ÉÒÔ°ïÎÒÃǽâ¾öÕâ¸öÎÊÌâ¡£
ÈçºÎÊ¹Ó ......
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/Êý¾Ý¿âà ......
mysql> create table testdate(
-> id int not null auto_increment primary key,
-> time date);
Query OK, 0 rows affected (0.30 sec)
mysql> insert into testdate(time) values('2010-4-23');
Q ......