php--拼接SQL 语句

阅读数:1286 发布时间:2016-06-29 16:29:57

作者:zzl005 标签: php sql

PHP 如何拼接 SQL 语句

$sql = "select *  from comment where comment_id = ".$comment_fid;

或:  

$sql = "select *  from comment where comment_id = '".$comment_fid."'";

//参数单独传递时
$sql = "insert into systemfunction (dep, fid, name) values ('".$dep."', '".$cid."', '".$name."') ";

//参数作为数组进行传递时

$params = array();//先定义参数数组
$params['name'] = $_REQUEST['name'];
$params['password'] = $_REQUEST['password'];
$params['level'] = $_REQUEST['level'];
...

public static function insert_student($params)
{
    $sql = "insert into admin (name,password, level, points, skills, projects, number, profile, keyword, time, picture, graduatetime, pageview, graduate, english, age, height, weight, school, region, realname) values ('".$params['name']."', '".$params['password']."', '".$params['level']."')";

   ....

}
$sql = "delete from systemfunction where id = '".$id."'";

//参数单独传递时
$sql = "update systemfunction set name = '".$name."' where id = '".$cid."' ";

//参数作为数组传递
$params = array();//先定义参数数组
$params['name'] = $_REQUEST['name'];
$params['password'] = $_REQUEST['password'];
$params['level'] = $_REQUEST['level'];
...

public static function update_student($params)

{
    $update_student  = "
        name = '".$params['name']."', 
        password = '".$params['password']."', 
        level = '".$params['level']."', 
        ...

        where id = '".$params['id']."'";
        $sql  = "update admin set ".$update_student;

   ....

}

相关文章推荐: