sqlÖÐ$ÊÇʲôÒâ˼
sql ÖÐ $ ·ûºÅÌåÏÖ²ÎÊýռλ·û£¬Ëü±»Ì滻ΪÅÌÎÊÖÐҪʹÓõÄÏÖʵֵ¡£$ ·ûºÅ¿ÉÌá¸ßÅÌÎʵĿɶÁÐÔ¡¢¿ÉÖØÓÃÐÔºÍÇå¾²ÐÔ¡£
SQL ÖÐ $ µÄ¼ÄÒå
ÔÚ SQL ÖУ¬$ ·ûºÅÖ¸µÄÊÇÒ»¸ö²ÎÊýռλ·û£¬ËüÌåÏÖÅÌÎÊÖÐÒªÌ滻ΪÏÖʵֵµÄ±äÁ¿¡£
ÔõÑùʹÓà $
ʹÓà $ ·ûºÅÓÐÁ½ÖÖ·½·¨£º
ÃüÃû²ÎÊý£º ʹÓà $parameter_name Óï·¨£¬ÆäÖÐ parameter_name ÊÇÄúҪʹÓõIJÎÊýµÄÃû³Æ¡£ÀýÈ磺
SELECT * FROM table_name WHERE id = $id;
µÇ¼ºó¸´ÖÆ
λÖòÎÊý£º ʹÓà $1¡¢$2 µÈÓï·¨£¬ÆäÖÐÊý×ÖÌåÏÖ²ÎÊýÔÚÅÌÎÊÖзºÆðµÄ˳Ðò¡£ÀýÈ磺
SELECT * FROM table_name WHERE id = $1 AND name = $2;
µÇ¼ºó¸´ÖÆ
Óŵã
ʹÓà $ ·ûºÅÓÐÒÔÏÂÓŵ㣺
¿É¶ÁÐÔ£ºËüʹÅÌÎʸüÒ×ÓÚÔĶÁºÍÃ÷È·£¬ÓÉÓÚ²ÎÊýÃû³Æ»òλÖÃÊÇÃ÷È·µÄ¡£
¿ÉÖØÓÃÐÔ£ºÊ¹ÓÃÃüÃû²ÎÊý£¬Äú¿ÉÒÔÖØÓÃÅÌÎʶø²»±Ø¸ü¸ÄÏÖʵֵ¡£
Çå¾²ÐÔ£ºËüÓÐÖúÓÚ±ÜÃâ SQL ×¢Èë¹¥»÷£¬ÓÉÓÚ²ÎÊýÖµ±»ÊÓΪÊý¾Ý¶ø²»ÊÇ´úÂë¡£
ʾÀý
ÒÔÏÂʾÀýÑÝʾÔõÑùʹÓà $ ·ûºÅ£º
-- ʹÓÃÃüÃû²ÎÊý SELECT * FROM users WHERE username = $username; -- ʹÓÃλÖòÎÊý SELECT * FROM products WHERE price > $1;
µÇ¼ºó¸´ÖÆ
ÔÚÕâЩʾÀýÖУ¬$username ºÍ $1 ÊDzÎÊýռλ·û£¬ÔÚÖ´ÐÐÅÌÎÊ֮ǰ±ØÐèÓÃÏÖʵֵÌæ»»ËüÃÇ¡£
ÒÔÉϾÍÊÇsqlÖÐ$ÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡