MySqlÎÞÏÞ·ÖÀàÊý¾Ý½á¹¹
ÎÞÏÞ·ÖÀàÊÇÎÒÃÇ¿ª·¢Öзdz£³£¼ûµÄÓ¦Óã¬ÏñÂÛ̳µÄµÄ°æ¿é£¬CMSµÄÀà±ð£¬Ó¦Óõĵط½Ìرð¶à¡£
ÎÒÃÇ×î³£¼û×î¼òµ¥µÄ·½·¨¾ÍÊÇÔÚMySqlÀïID ,parentID,name£º
ÓŵãÊǼòµ¥£¬½á¹¹¼òµ¥¡£
ȱµãÊÇЧÂʲ»¸ß£¬ÒòΪÿһ´ÎµÝ¹é¶¼Òª²éѯÊý¾Ý¿â£¬¼¸°ÙÌõÊý¾Ý¿âʱ¾Í²»ÊǺܿìÁË£¡
´æ´¢Ê÷ÊÇÒ»ÖÖ³£¼ûµÄÎÊÌ⣬¶àÖÖ½â¾ö·½°¸¡£Ö÷ÒªÓÐÁ½ÖÖ·½·¨£ºÁÚ½Ó±íµÄÄ£ÐÍ£¬²¢ÐÞ¸ÄÊ÷Ç°Ðò±éÀúËã·¨¡£
ÎÒÃǽ«Ì½ÌÖÕâÁ½ÖÖ·½·¨µÄ½ÚÄܵȼ¶µÄÊý¾Ý¡£ÎÒ»áʹÓÃÊ÷´ÓÒ»¸öÐé¹¹µÄÍøÉÏʳƷÉ̵ê×÷Ϊһ¸öÀý×Ó¡£ÕâʳƷÉ̵ê×éÖ¯ÆäʳƷÀ࣬ͨ¹ýÑÕÉ«ºÍÀàÐÍ¡£Õâ¿ÃÊ÷¿´ÆðÀ´ÏñÕâÑù£º
ÏÂÃæÎÒÃǽ«ÓÃÁíÍâÒ»ÖÖ·½·¨£¬Õâ¾ÍÊÇÔ¤ÅÅÐò±éÀúÊ÷Ëã·¨(modified preorder tree traversal algorithm)
ÕâÖÖ·½·¨´ó¼Ò¿ÉÄܽӴ¥µÄ±È½ÏÉÙ£¬³õ´ÎʹÓÃÒ²²»ÏñÉÏÃæµÄ·½·¨ÈÝÒ×Àí½â£¬µ«ÊÇÓÉÓÚÕâÖÖ·½·¨²»Ê¹Óõݹé²éѯËã·¨£¬Óиü¸ßµÄ²éѯЧÂÊ¡£
ÎÒÃÇÊ×ÏȽ«¶à¼¶Êý¾Ý°´ÕÕÏÂÃæµÄ·½Ê½»ÔÚÖ½ÉÏ£¬ÔÚ¸ù½ÚµãFoodµÄ×ó²àдÉÏ 1 È»ºóÑØ×ÅÕâ¸öÊ÷¼ÌÐøÏòÏ ÔÚ Fruit µÄ×ó²àдÉÏ 2 È»ºó¼ÌÐøÇ°½ø£¬ÑØ×ÅÕû¸öÊ÷µÄ±ßÔµ¸øÿһ¸ö½Úµã¶¼±êÉÏ×ó²àºÍÓÒ²àµÄÊý×Ö¡£×îºóÒ»¸öÊý×ÖÊDZêÔÚFood ÓÒ²àµÄ 18¡£ ÔÚÏÂÃæµÄÕâÕÅͼÖÐÄã¿ÉÒÔ¿´µ½Õû¸ö±êºÃÁËÊý×ֵĶ༶½á¹¹¡££¨Ã»Óп´¶®£¿ÓÃÄãµÄÊÖÖ¸Ö¸×ÅÊý×Ö´Ó1Êýµ½18¾ÍÃ÷°×Ôõô»ØÊÂÁË¡£»¹²»Ã÷°×£¬ÔÙÊýÒ»±é£¬×¢ÒâÒƶ¯ÄãµÄÊÖÖ¸£©¡£
ÕâЩÊý×Ö±êÃ÷Á˸÷¸ö½ÚµãÖ®¼äµÄ¹Øϵ£¬"Red"µÄºÅÊÇ3ºÍ6£¬ËüÊÇ "Food" 1-18 µÄ×ÓËï½Úµã¡£ ͬÑù£¬ÎÒÃÇ¿ÉÒÔ¿´µ½ ËùÓÐ×óÖµ´óÓÚ2ºÍÓÒֵСÓÚ11µÄ½Úµã ¶¼ÊÇ"Fruit" 2-11 µÄ×ÓËï½Úµã
ÈçͼËùʾ£º
ÕâÑùÕû¸öÊ÷×´½á¹¹¿ÉÒÔͨ¹ý×óÓÒÖµÀ´´æ´¢µ½Êý¾Ý¿âÖС£¼ÌÐø֮ǰ£¬ÎÒÃÇ¿´Ò»¿´ÏÂÃæÕûÀí¹ýµÄÊý¾Ý±í¡£
×¢Ò⣺ÓÉÓÚ"left"ºÍ"right"ÔÚ SQLÖÐÓÐÌØÊâµÄÒâÒ壬ËùÒÔÎÒÃÇÐèÒªÓÃ"lft"ºÍ"rgt"À´±íʾ×óÓÒ×ֶΡ£ ÁíÍâÕâÖֽṹÖв»ÔÙÐèÒª"parent"×Ö¶ÎÀ´±íʾÊ÷×´½á¹¹¡£Ò²¾ÍÊÇ ËµÏÂÃæÕâÑùµÄ±í½á¹¹¾Í×ã¹»ÁË¡£
SELECT * from tree WHERE lft BETWEEN 2 AND 11;
¿´µ½ÁË°É£¬Ö»ÒªÒ»¸ö²éѯ¾Í¿ÉÒԵõ½ËùÓÐÕâЩ½Úµã¡£ÎªÁËÄܹ»ÏñÉÏÃæµÄµÝ¹éº¯ÊýÄÇÑùÏÔʾÕû¸öÊ÷×´½á¹¹£¬ÎÒÃÇ»¹ÐèÒª¶ÔÕâÑùµÄ²éѯ½øÐÐÅÅÐò¡£ÓýڵãµÄ×óÖµ½øÐÐÅÅÐò£º
SELECT * from tree WHERE lft BETWEEN 2 AND 11 ORDER BY lft ASC;
ÄÇôij¸ö½Úµãµ½µ×ÓжàÉÙ×ÓËï½ÚµãÄØ£¿ºÜ¼òµ¥£¬×ÓËï×ÜÊý=(ÓÒÖµ-×óÖµ-1)/2&nb
Ïà¹ØÎĵµ£º
ÏÈÇ°ÔÚ²âÊÔmysql connect c++½Ó¿ÚµÄʱºòÔËÐÐÆä¹Ù·½ÌṩµÄÀý×Ó
21.5.5.6. MySQL Connector/C++ Complete Example 2
The following code shows a complete example of how to use MySQL Connector/C++:
/* Copyright 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify ......
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON bankaccount.*
-> TO 'custom'@'localhost'
-> IDENTIFIED BY 'password';
mysql> GRANT SELECT,INS ......
×î½üµÄÏîÄ¿ÖÐʹÓÃÁËMySQLÊý¾Ý¿â£¬Ò»Ð©MySQLµÄÐÂÓû§ÔÚÅäÖÃʹÓÃʱ»¹ÓÐЩ²»¹»ÊìÁ·£¬ÌØÔڴ˼Ǽ£¬·½±ã¿ª·¢ÍŶÓʹÓ㬸ÃÎÄÕÂËùÉæ¼°ÄÚÈݾù¿ÉÒÔÔÚMySQL²Î¿¼ÊÖ²áµÚ¶þÕ“°²×°MySQL”ÖÐÕÒµ½¡£MySQL°²×°ºó×Ô´øÁËÓ¢ÎIJο¼ÊֲᣬҲ¿ÉÒÔÔÚhttp://dev.mysql.com/doc/refman/5.1/zh/index.html²é¿´ÖÐÎÄ°æ±¾£ ......
·ÀÖ¹×¢ÈëµÄ¼¸ÖÖ°ì·¨
ÆäʵÔÀ´¾ÍÊÇÎÒÃÇÐèÒª¹ýÂËһЩÎÒÃdz£¼ûµÄ¹Ø¼ü×ֺͷûºÏÈ磺
Select£¬insert£¬update£¬delete£¬and£¬*£¬µÈµÈ
function inject_check($sql_str) {
return eregi('select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file
|outfile', $sql_str); & ......