Ҳ̸ PHP ºÍ MYSQL

5年以前  |  阅读数:679 次  |  编程语言:PHP 

½«PHPºÍMYSQLºÏÀiÇÒÓÐЧµÄ½aºÏÔÚÒ»Æð¿ÉÒÔÖÆ×÷³o¾«ÖµÄÊý¾Ý¿aÍøÕ¾¡£MYSQLÊÇÒ»ÖÖСÐ͵ģ¬½oÃܵÄÊý¾ÝþÎñÆ÷£¬Ö§³Ö±e×¼SQL¡£ËuÔÚUNIXºÍWINDOWS»¾³Ï¶¼Äܹ»Ê¹Óá£
PHPºÍMYSQL¶¼ÊÇÃaѵĿªÅÔ´Âe¡£ËuÃǵĽaºÏ¿ÉÒÔÔÚWINDOWSÖТչ£¬ÔÚUNIXÖÐ×oþÎñ¡£PHPÒ²Ö§³ÖÆaËuÒ»Ð(C)Êý¾Ý¿a°uÀ¨PostgreSQL.

ÏÂÃaeÓÐÒ»¸oÀý×Ó£º
Ê×ÏÈÄaÒѾ­°²×°ÁËPHP¼°MYSQL. Õa¸o¼oµ¥µÄ½Å±¾Àý×ÓÊÇ´ÓÊý¾Ý¿aÖжÁÈ¡Êý¾ÝÈ»ºoÏÔʾ³oÀ´¡£

$db = mysql_connect("localhost", "root");
mysql_select_db("mydb", $db);
$result = mysql_query("SELECT * FROM books",$db);
echo "Title: ".mysql_result($result,0,"title")."
\n";
echo "Author: ".mysql_result($result,0,"author")."
\n";
echo "Price: ".mysql_result($result,0,"price")."
\n";

?>

º¯Êýmysql_connect()ÊÇÖ¸ÔÚÖ¸¶¨µÄÖ÷»uÉÏͨ¹ýÓû§Ãu£¨Ò²¿Éͨ¹ýÖ¸¶¨ÃÜÂe£(C)Á¬½ÓÒ»¸oMYSQL*þÎñÆ÷¡£±aÁ¿ $db ÊÇÓÃÀ´Ìa½»Õa¸oÁ¬½Ó¡£.

mysql_select_db() Ö¸¶¨Êý¾Ý¿aÓÃÔÚºoÃaeµÄÒÉÎÊ¡£º¯Êý mysql_query() ÊÇ¢ËÍ SQL ÒÉÎʵ½ MySQL ½øÐÐÖ´ÐÐ £¬ ½a¹uµ»Ø²¢´ae´¢ÔÚ±aÁ¿ $result ÖÐ.

×iºo mysql_result() º¯ÊýÊǵóo½a¹u¡£

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8