PHP·ÃÎÊMySQLÊý¾Ý¿âº¯Êý¼ò½é
PHP·ÃÎÊMySQLÊý¾Ý¿âº¯Êý¼ò½é
1. ½øÐÐÊý¾Ý¿âÁ¬½Ó
Á¬½ÓÊý¾Ý¿â·þÎñÆ÷£¬¾ÍÊÇ¿Í»§¶ËÏò¼ºÔËÐеÄÊý¾Ý¿â·þÎñÆ÷·¢³öÁ¬½ÓÇëÇó£¬
³É¹¦ÒÔºó¾Í¿ÉÒÔ¶ÔÊý¾Ý¿â½øÐÐÏàÓ¦²Ù×÷£¬ÓÉÓÚÓû§µÄȨÏÞ²»Í¬£¬ËùÄܽø
ÐеIJÙ×÷Ò²²»Ò»Ñù¡£PHPÌṩÁËһϵÁÐMySQL²Ù×÷µÄº¯Êý£¬ÓÃÀ´Á¬½ÓÊý¾Ý
¿âµÄº¯ÊýÓÐÁ½¸ö£¬·Ö±ðÊÇ£ºmysql_connect()ºÍmysql_pconnect()¡£
ÏÂÃæÔÚ¶Ô³£Óõļ¸¸öº¯Êý×÷¼òµ¥½éÉܺó£¬ÓÃÒ»¸öÀý×ÓÀ´ËµÃ÷ÔÚPHP½Å±¾ÖÐ
×Ô¶¯Á¬½ÓÊý¾Ý¿âµÄ·½·¨¡£
1.1 mysql_connectº¯Êý
º¯Êýµ÷ÓøñʽÈçÏ£º
int mysql_connect([string hostname] [:port][, string usename]
[, string password]);
²ÎÊýÁбíÖеÄport²ÎÊý±íʾÊý¾Ý¿â·þÎñÆ÷µÄ¶Ë¿ÚºÅ£¬Ò»°ãÓÃËüµÄĬÈ϶Ë
¿Ú3306¾Í¿ÉÒÔÁË¡£Èç¹û²»ÌîÈκβÎÊý£¬ÔòĬÈϵÄhostnameΪ"localhost",
usnameΪ"root", passwordΪ¿Õ¡£µ±È»£¬Óû§¿ÉÒÔÖ¸¶¨×Ô¼ºËùÒªÁ¬½ÓµÄ
Ö÷»úÃû¡¢Óû§Ãû¡¢Óû§ÃÜÂ룬À´Á¬½ÓÖ¸¶¨µÄÊý¾Ý¿â¡£
º¯ÊýÖ´Ðгɹ¦£¬·µ»ØÒ»¸öintÀàÐ͵ÄÁ¬½ÓºÅ£¬Ö´ÐÐʧ°Ü£¬·µ»ØfalseÖµ¡£
Àý1.1£º
<?PHP
//Á¬½ÓÊý¾Ý¿â·þÎñÆ÷
$connect = mysql_connect("localhost","user","password");
if($connect)
{
echo "Á¬½Ó³É¹¦"; //Á¬½Ó³É¹¦£¬ÏÔʾ“Á¬½Ó³É¹¦";
}
else
{
echo "Á¬½Óʧ°Ü"; //Á¬½Óʧ°Ü£¬ÏÔʾ"Á¬½Óʧ°Ü";
}
?>
ÔÚÉÏÀýÖУ¬Èômysql_connectº¯ÊýÖ´ÐÐʧ°Ü£¬½«ÏÔʾÏàÓ¦µÄ´íÎóÌáʾ£¬
¶øºó¼ÌÐøÍùÏÂÖ´ÐС£Èç¹ûÏëÆÁ±ÎϵͳµÄ´íÎóÌáʾ²¢ÔÚʧ°Üºó½áÊø³ÌÐò
Ïà¹ØÎĵµ£º
UTF8 ĬÈÏУ¶Ô¼¯ÊÇ utf8_general_ci , Ëü²»ÊÇ°´ÕÕÖÐÎÄÀ´µÄ¡£ÄãÐèҪǿÖÆÈÃMySQL°´ÖÐÎÄÀ´ÅÅÐò¡£
select
*
from
core_vender_info
order
by
convert
(vender_abbrev USING gbk) COLLATE gbk_chinese_ci
......
µÚÒ»²½£ºÏÂÔØ°²×°³ÌÐò
£¨1£© Apache2.2.4°æÏÂÔØ£¬µØÖ·£ºhttp://httpd.apache.org/download£¬Ñ¡Ôñ
apache_2.2.4-win32-x86-no_ssl.msi£¬´óÔ¼4M¶à¡£
£¨2£©PHP5.2.3°æÏÂÔØ£¬ µØÖ·£ºhttp://www.php.net/downloads.php£¬Ñ¡ÔñWindows BinariesÏÂÃæµÄPHP5.2.3.zip package£¬Ëü¶ÔÓ¦php-5.2.3-Win32.zipÎļþ£¬´óÔ¼9M¶à¡£
µÚ¶þ² ......
/*************Ê®½øÖÆ´óÕûÊýÏà³Ë****************/
/*********
* $A£¬$B¾ùΪ×Ö·û´®
*/
function multipication ($A,$B){
$sResult = "";
  ......
function _processBeforeDb($str)
{
$str = str_replace ( array ('<', '>' ), array ('<' , '>' ), $str );
if (!get_magic_quotes_runtime()){
return addslashes($str);
}
else
{
return $str;
}
}
......