sqlÖÐ$µÄ×÷ÓÃ
sql ÖÐ $ ·ûºÅµÄ×÷ÓÃÓÐÈý¸ö£ºÌåÏÖ²ÎÊýռλ·û£¬ÀýÈç select * from users where id = $1;תÒåÌØÊâ×Ö·û£¬ÀýÈç select * from users where name = ‘$name’;ÌåÏÖ±äÁ¿£¬ÀýÈçÔÚ postgresql ÖУ¬$$name$$ ÌåÏֻỰ±äÁ¿¡£
SQL ÖÐ $ ·ûºÅµÄ×÷ÓÃ
ÔÚ SQL ÖУ¬$ ·ûºÅ¾ßÓÐÒÔÏÂ×÷Óãº
ÓÃÓÚÌåÏÖ²ÎÊýռλ·û
$ ·ûºÅ×î³£ÓõÄÓÃ;ÊÇÌåÏÖ²ÎÊýռλ·û¡£ÔÚ×¼±¸Óï¾äÖУ¬Ê¹Óà $ ·ûºÅÀ´Ö¸¶¨²ÎÊýµÄλÖã¬È»ºóÔÚÖ´ÐÐÓï¾äʱÌṩÏÖʵ²ÎÊýÖµ¡£ÕâÓÐÖúÓÚ±ÜÃâ SQL ×¢Èë¹¥»÷£¬²¢Ìá¸ß³ÌÐòµÄЧÂʺͿÉά»¤ÐÔ¡£
ʾÀý£º
SELECT * FROM users WHERE id = $1;
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬$1 ռλ·ûÌåÏÖÒ»¸öÕûÐͲÎÊý£¬½«ÔÚÖ´ÐÐÓï¾äʱÌṩ¡£
ÓÃÓÚתÒåÌØÊâ×Ö·û
µ±ÐèÒªÔÚ×Ö·û´®ÖаüÀ¨ÌØÊâ×Ö·ûʱ£¬¿ÉÒÔʹÓà $ ·ûºÅÀ´×ªÒåÕâЩ×Ö·û£¬ÒÔ±ÜÃâÆÊÎöÆ÷½«ËüÃÇÊÓΪ SQL Óï¾äµÄÒ»²¿·Ö¡£
ʾÀý£º
SELECT * FROM users WHERE name = '$name';
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬$name ±äÁ¿°üÀ¨Ò»¸ö×Ö·û´®Öµ£¬¿ÉÄÜ°üÀ¨ÌØÊâ×Ö·û(ÀýÈçµ¥ÒýºÅ)¡£Ê¹Óà $ ·ûºÅתÒåµ¥ÒýºÅ¿ÉÒÔÈ·±£Ëü²»»á±»ÆÊÎöÆ÷Ú¹ÊÍΪÓï¾ä¿¢Ê·û¡£
ÓÃÓÚÌåÏÖ±äÁ¿
ÔÚijЩÇéÐÎÏ£¬$ ·ûºÅ¿ÉÒÔÓÃÓÚÌåÏÖ±äÁ¿¡£ÀýÈ磬ÔÚ PostgreSQL ÖУ¬$ ·ûºÅ¿ÉÒÔÌåÏֻỰ±äÁ¿¡£
ʾÀý£º
SELECT * FROM users WHERE name = $$name$$;
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬$$name$$ ÌåÏÖÒ»¸ö»á»°±äÁ¿£¬½«ÔÚÓï¾äÖ´ÐÐÇ°ÆÊÎö¡£
ÒÔÉϾÍÊÇsqlÖÐ$µÄ×÷ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡