写CDB类库的时候,就有一个查询是要求写出一个,具有可变参数个数的函数,类似于sprintf,fsql定义了数据格式,v1, v2等变量定义了要替换的值,然后将替换后的字符串作为数据库查询进行执行.
先举一个实现后的例子:
queryf("select * from glove_user where name = '%s' and site = '%s'", 'glove', 'glovely.info');
这其实就是一个select语句,其中不同的地方就是第一个参数中的name的值%s用后面的’glove’来替换,site的值%s用后面的’glovely.info’来替换,这些可以替换的参数是不限定个数的.
也就是说这个函数像我们用的sprintf一样,是带有不定个数的参数的.
实例1:
两个需要解释:
1.mysqli_real_escape_string于mysql_real_escape_string
一、mysql中:
mysql_escape_string
mysql_real_escape_string
二、mysqli中:
escape_string
real_escape_string
mysqli_real_escape_string
mysqli_escape_string //是mysqli_real_escape_string的别名
You should use mysql_real_escape_string() instead!
This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler as its first argument and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current character set.
2.call_user_func_array
Result:
# php call_user_func_array.php
foobar got one and two
foo::bar got three and four
先举一个实现后的例子:
queryf("select * from glove_user where name = '%s' and site = '%s'", 'glove', 'glovely.info');
这其实就是一个select语句,其中不同的地方就是第一个参数中的name的值%s用后面的’glove’来替换,site的值%s用后面的’glovely.info’来替换,这些可以替换的参数是不限定个数的.
也就是说这个函数像我们用的sprintf一样,是带有不定个数的参数的.
实例1:
两个需要解释:
1.mysqli_real_escape_string于mysql_real_escape_string
一、mysql中:
mysql_escape_string
mysql_real_escape_string
二、mysqli中:
escape_string
real_escape_string
mysqli_real_escape_string
mysqli_escape_string //是mysqli_real_escape_string的别名
You should use mysql_real_escape_string() instead!
This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler as its first argument and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current character set.
2.call_user_func_array
Result:
# php call_user_func_array.php
foobar got one and two
foo::bar got three and four
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/4387/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表