在执行插入查询后获取插入行?

时间:2016-09-13 18:22:19

标签: php mysql

所以我基本上做的是我想在插入功能之后立即将用户重定向到art.php?id=$id,例如:

所以这是我的$user->insertArt函数:

public function insertArt($description,$image,$creator,$width,$height){
    try {
        $sql = "INSERT into arts (description,id,image,creator,post_date,width,height) values (:description,UUID_SHORT(),:image,:creator,NOW(),:width,:height)";
        $stmt = $this->con->prepare($sql);
        $stmt->bindValue(':description',$description,PDO::PARAM_STR);
        $stmt->bindValue(':image',$image,PDO::PARAM_STR);
        $stmt->bindValue(':creator',$creator,PDO::PARAM_STR);
        $stmt->bindValue(':width' , $width, PDO::PARAM_INT);
        $stmt->bindValue(':height' , $height, PDO::PARAM_INT);
        $stmt->execute();
        return true;
     }catch(PDOException $e){echo $e->errorInfo; return false;}
} 

所以我正在尝试做的就像下面一样,用$id取代$user->in来获取if ($user->insertArt($description, $image['url'], $creator, $width, $height)) { unlink(realpath('uploads/' . $newFileName)); //redirect user to the ID. header("Location:art.php?id=$id"); // replace $id with UUID_SHORT from the query } } 的id行。

json api plugin

0 个答案:

没有答案