×ðÁú¿­Ê±

ÔõôʹÓÃthinkphp5½«¹ýʧSQLÓï¾ä´òÓ¡µ½ÈÕÖ¾ÖÐ

Ò»¡¢¹ýʧSQLÓï¾äµÄÔµ¹ÊÔ­ÓÉ

¹ýʧSQLÓï¾äÔÚÓ¦ÓóÌÐòÖкÜÄÑ×èÖ¹ £¬ÕâЩ¹ýʧÓÐʱºÜÄÑʶ±ð £¬Ê¹ÓÃthinkphp5¿ÉÒÔÒÔ¸üÓÅÑŵķ½·¨²¶»ñºÍ´¦Öóͷ£ÕâЩ¹ýʧ¡£ÔÚ¿ª·¢Àú³ÌÖÐ £¬¹ýʧSQLÓï¾ä¿ÉÄÜ»áÓÉÒÔÏÂÔµ¹ÊÔ­ÓÉÒýÆð£º

SQLÓï·¨¹ýʧ

µ¼ÖÂSQLÓï·¨¹ýʧµÄÔµ¹ÊÔ­ÓÉͨ³£ÊDZàдµÄSQLÓï¾ä±£´æ¹ýʧ»ò²»ÍêÕû¡£ÕâÊÇ×î³£¼ûµÄ¹ýʧ֮һ £¬ÓÉÓÚ×ÝÈ»ÊÇ×îÂÄÀú¸»ºñµÄ¿ª·¢Ö°Ô±Ò²»áÔÚÓï·¨ÉÏ·¸¹ýʧ¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

Êý¾Ý¿âÅþÁ¬ÎÊÌâ

Ó¦ÓóÌÐòδÄÜÅþÁ¬µ½Êý¾Ý¿âÊÇÓÉÓÚÊý¾Ý¿âÅþÁ¬ÎÊÌâËùÖ £¬Õâ¿ÉÄܻᵼÖÂSQLÓï¾ä¹ýʧ¡£´ËÀàÎÊÌâͨ³£ÊÇÓÉÓÚÊý¾Ý¿âÉèÖò»×¼È·¡¢Êý¾Ý¿âЧÀÍÆ÷ûÓÐÆô¶¯»òÕßÎÞ·¨´¦Öóͷ£ÇëÇóÒýÆðµÄ¡£

Êý¾Ý¿â±í½á¹¹¹ýʧ

ÈôÊÇÊý¾Ý¿â±í½á¹¹·ºÆð¹ýʧ £¬ÄÇôSQLÅÌÎʾÍÓпÉÄÜÎÞ·¨Íê³É £¬ÆäЧ¹ûÒ»¶¨ÊǹýʧµÄ¡£³£¼û¹ýʧ֮һÊǵ±±í½á¹¹±¬·¢¸ü¸Äʱ £¬ÅÌÎÊÖеÄ×ֶοÉÄÜÓëÒÑɾ³ý»ò¸ü¸Ä×Ö¶ÎµÄ±í²»Æ¥Åä¡£

¶þ¡¢ÔõÑù´òÓ¡¹ýʧSQLÓï¾äµ½ÈÕÖ¾ÖÐ

ÔÚThinkPHP5ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÈÕÖ¾¼Í¼¹¦Ð§À´²¶»ñºÍÆÊÎö¹ýʧµÄSQLÓï¾ä¡£ÉúÑĹýʧµÄSQLÓï¾ä¿ÉÒÔ×ÊÖúÎÒÃǸü¿ìµØ·¢Ã÷ÎÊÌâ £¬²¢¸üºÃµØ´¦Öóͷ£SQL¹ýʧ¡£

ÒÔÏÂÊÇÒ»¸öʾÀý £¬ÑÝʾÔõÑùÉèÖÃÈÕÖ¾¼Í¼²¢²¶»ñ¹ýʧSQLÓï¾ä£º

Ê×ÏÈ £¬ÐèÒªÔÚÓ¦ÓóÌÐòµÄconfig.phpÎļþÖÐÔöÌíÈçÏÂÉèÖãº

// ¿ªÆôSQLÈÕÖ¾¼Í¼
'trace' => [
    // ¼Í¼SQLÈÕÖ¾
    'type' => 'sql',
    // SQLÈÕÖ¾¼Í¼·½·¨
    'record_sql' => true,
],

µÇ¼ºó¸´ÖÆ

Õ⽫ÆôÓÃSQLÈÕÖ¾¼Í¼ £¬²¢ÔÊÐí¼Í¼¹ýʧSQLÓï¾ä¡£È·±£¼Í¼SQLÅÌÎʱØÐèÉèÖÃ’record_sql’ => true¡£ÈôÊǸÃֵΪfalse £¬Ôò²»»á¼Í¼SQLÅÌÎÊ £¬Ò²²»»á¼Í¼Òì³£¡£

ÉèÖÃÍêÉèÖÃÒÔºó £¬ÎÒÃÇ¿ÉÒÔÔËÐÐÓ¦ÓóÌÐò²¢Éó²éÈÕÖ¾Îļþ¡£Í¨¹ýʹÓÃÈÕÖ¾¼Í¼ £¬ÎÒÃÇ¿ÉÒÔÇáËɲéÕÒ²¢½â¾ö¹ýʧSQLÓï¾äÎÊÌâ¡£

Èý¡¢ÆäËûµ÷ÊÔ¼¼ÇÉ

³ýÁËʹÓÃÈÕÖ¾¼Í¼֮Íâ £¬ÉÐÓÐÆäËûһЩ¼¼ÇÉ¿ÉÒÔ×ÊÖúÎÒÃDz¶»ñºÍʶ±ð¹ýʧSQLÓï¾ä£º

ʹÓÃDebug¹¤¾ß

DebugÊÇÒ»¸ö¼¯³É¹¤¾ß £¬¿ÉÒÔ×ÊÖúÄúʶ±ð¹ýʧµÄSQLÓï¾äºÍÆäËûÎÊÌâ £¬ËüÊÇThinkPHP5ËùÌṩµÄ¡£Ö»Ðè¼òÆÓµØÉèÖõ÷ÊÔģʽ²¢»á¼ûÓ¦ÓóÌÐò¼´¿ÉʹÓÃDebug¹¤¾ß¡£

´òÓ¡SQL¹ýʧ

ͨ¹ýʹÓÃtry-catch¿éºÍException £¬ÎÒÃÇ¿ÉÒÔ²¶»ñSQL¹ýʧ²¢´òÓ¡³öÀ´£º

try {
    // Ö´ÐÐÅÌÎʲÙ×÷
} catch (\Exception $e) {
    // ´òÓ¡¹ýʧµ½¿ØÖÆ̨
    echo $e->getMessage();
}

µÇ¼ºó¸´ÖÆ

ÓÉÓÚÊý¾Ý¿âÅÌÎʹýʧͨ³£ÓëSQLÓï·¨¹ýʧÓйØ £¬ÎÒÃÇ¿ÉÒÔ½«¹ýʧ´òÓ¡µ½¿ØÖÆ̨ £¬½øÒ»²½È·¶¨ÎÊÌâµÄ»ù´¡Ôµ¹ÊÔ­ÓÉ¡£

ʹÓÃPHPMyAdminµ÷ÊÔ

ÈôÊÇʹÓÃMySQL×÷ΪÊý¾Ý¿â £¬PHPMyAdmin¿ÉÒÔÓÃ×÷Ò»Ñùƽ³£µÄµ÷ÊÔ¹¤¾ß¡£Í¨¹ýPHPMyAdminµÄ¿ÉÊÓ»¯½çÃæ £¬ÎÒÃÇ¿ÉÒÔÇáËɵØÉó²éºÍÆÊÎöSQLÅÌÎÊ¡£

ÒÔÉϾÍÊÇÔõôʹÓÃthinkphp5½«¹ýʧSQLÓï¾ä´òÓ¡µ½ÈÕÖ¾ÖеÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿