¼ÓÈëÊÕ²Ø | ÉèΪÊ×Ò³ | »áÔ±ÖÐÐÄ | ÎÒҪͶ¸å Àî´óͬ £¨https://www.lidatong.com.cn/£©- ¿Æ¼¼¡¢½¨Õ¾¡¢¾­Ñé¡¢ÔÆ¼ÆËã¡¢5G¡¢´óÊý¾Ý,Õ¾³¤Íø!
µ±Ç°Î»Ö㺠Ê×Ò³ > Õ¾³¤Ñ§Ôº > PHP½Ì³Ì > ÕýÎÄ

ÎªÊ²Ã´ÒªÑ¹ÖÆPHP´íÎó£¿

·¢²¼Ê±¼ä£º2020-12-13 21:42:28 ËùÊôÀ¸Ä¿£ºPHP½Ì³Ì À´Ô´£ºÍøÂçÕûÀí
µ¼¶Á£ºÎÒÏëÖªµÀΪʲôÄã»á¡°ÒÖÖÆ¡± PHP´íÎó.ÎÒÃ÷ÏÔ¿´µ½´íÎó²úÉúµÄ¶îÍ⾯¸æÏßµÄÇø±ð,µ«ÒÖÖÆËüÊÇ·ñÓкô¦£¿ Access denied for user 'user'@'localhost' (using password: YES) VS Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user
ÎÒÏëÖªµÀΪʲôÄã»á¡°ÒÖÖÆ¡± PHP´íÎó.ÎÒÃ÷ÏÔ¿´µ½´íÎó²úÉúµÄ¶îÍ⾯¸æÏßµÄÇø±ð,µ«ÒÖÖÆËüÊÇ·ñÓкô¦£¿

Access denied for user 'user'@'localhost' (using password: YES)

VS

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost'       (using password: YES) in (deleted) on line 8
Access denied for user 'user'@'localhost' (using password: YES)

Èç¹ûÊÇÕâÑù,ÎÒÓ¦¸ÃÑø³ÉÔÚÎÒµÄPHP³ÌÐòÖеÄMySQL²éѯ¿ªÍ·ÊäÈë@µÄϰ¹ßÂð£¿

½â¾ö·½·¨

ÄãÓ¦¸Ã»ý¼«µØÑø³ÉÒÖÖÆ´íÎóµÄϰ¹ß.´íÎóÊÇÓÐÔ­ÒòµÄ.Ïà·´,ÔÚ´úÂëÖÐÕýÈ·ºÍ·ÀÓùµØ´¦ÀíËüÃÇ,²¢²»¶ÏÍêÉÆ´úÂë,Ö±µ½´íÎóÏûʧ.

ÄãÓ¦¸Ã×öµÄÊÂÇéÈçÏ£º

$conn = mysql_connect($host,$user,$pass);

// Always test to see if your action/connection/whatever was successful
if (!$conn) {
  // something went wrong.  handle the error
  // Display a message for the user,write a message to `error_log()`,whatever's appropriate
}
else mysql_select_db($dbname);

ÔÚÉú²úϵͳÉÏ,ÄúÓÀÔ¶²»Ó¦¸ÃÏÔʾ´íÎó,ÒòΪËü¿ÉÄÜ»áй¶ÄúµÄ´úÂëºÍÊý¾Ý¿âµÄÏêϸÐÅÏ¢.Ïà·´,ÔÚphp.ini»òÔËÐÐʱ¹Ø±Õdisplay_errors£º

// In development and production,make sure all errors are reported
error_reporting(E_ALL & E_STRICT);

// In development show all errors on screen so you handle them as they occur
ini_set('display_errors',1);

// In production turn them off
ini_set('display_errors',0);

ÊÂʵÉÏ,ʹÓÃ@µÄ´íÎóÒÖÖÆÊÇPHPÔã¸âÁ·Ï°in this classic question.µÄµÚ¶þ´óͶƱ

£¨±à¼­£ºÀî´óͬ£©

¡¾ÉùÃ÷¡¿±¾Õ¾ÄÚÈݾùÀ´×ÔÍøÂ磬ÆäÏà¹ØÑÔÂÛ½ö´ú±í×÷Õ߸öÈ˹۵㣬²»´ú±í±¾Õ¾Á¢³¡¡£ÈôÎÞÒâÇÖ·¸µ½ÄúµÄȨÀû£¬Ç뼰ʱÓëÁªÏµÕ¾³¤É¾³ýÏà¹ØÄÚÈÝ!

    ÍÆ¼öÎÄÕÂ
      ÈȵãÔĶÁ