要求我输入一个sql的select语句,要在每张表的前面加上一个前缀
例如
输入select * from student
转换为:select * from student_student输入select * from student where id=1
转换为:select * from student_student where id=1嵌套查询里面的表也是一样
请问应该怎么样实现
例如
输入select * from student
转换为:select * from student_student输入select * from student where id=1
转换为:select * from student_student where id=1嵌套查询里面的表也是一样
请问应该怎么样实现
$fromPos = stripos ( $_sql, "from" ); //获得第一次“from”出现的位置。
$wherePos = stripos ( $_sql, "where" ); //获得第一次 where 出现的位置
$from_sql = substr ( $_sql, $fromPos ); //from部分语句 查询条件 $tableName = trim ( substr ( $_sql, $fromPos + 4, $wherePos - $fromPos - 4 ) ); //所操纵的数据表名
表名取到了,自己去拼吧
$old_sql = "select * from student";
$new_sql = add_student($old_sql);
echo $new_sql ;function add_student($str)
{
$str = str_replace('student','student_student',$str);
return $str;
}