exec("DELETE FROM t_segment_index WHERE vs_uuid='$vsuuid'")">
当前位置:Gxlcms > PHP教程 > php变量访问权限问题?

php变量访问权限问题?

时间:2021-07-01 10:21:17 帮助过:31人阅读

方法代码:

function deleteSegment($vsuuid) {
    $num = db("test")->exec("DELETE FROM t_segment_index WHERE vs_uuid='$vsuuid'");
    if($num == 1) {
        $del = db("test")->exec("DELETE FROM t_video_segment WHERE vs_uuid='$vsuuid'");
        if($del == 1){
            $vsu = $vsuuid;
            $videoMsg = db("test")->getQuery("SELECT * FROM `t_video` where v_segments_list like '%$vsuuid%' limit 1");
            if(empty($videoMsg))
                return $del;
            $segments = $videoMsg[0]["v_segments_list"];
            $v_uuid = $videoMsg[0]["v_uuid"];
            $oldSegmentArray = explode("\n", $segments);
            $newSegmentArray = array_filter($oldSegmentArray, function($s){
                if($s === $vsuuid)
                    return false;
                else
                    return true;
            });
            $newSegments = implode("\n", array_values($newSegmentArray));
            $updateV = db("test")->exec("UPDATE t_video SET v_segments_list = '$newSegments' WHERE v_uuid='$v_uuid'");
            return 1;
        } else
            return 0;
    } else
        return 0;
}

代码执行到if($s === $vsuuid)的时候报错如下:
Notice: Undefined variable: vsuuid in /Applications/XAMPP/xamppfiles/htdocs/waaa-web/runtime/service_Admin.php on line 1526


请问是什么原因导致的?该怎么解决呢?

回复内容:

方法代码:

function deleteSegment($vsuuid) {
    $num = db("test")->exec("DELETE FROM t_segment_index WHERE vs_uuid='$vsuuid'");
    if($num == 1) {
        $del = db("test")->exec("DELETE FROM t_video_segment WHERE vs_uuid='$vsuuid'");
        if($del == 1){
            $vsu = $vsuuid;
            $videoMsg = db("test")->getQuery("SELECT * FROM `t_video` where v_segments_list like '%$vsuuid%' limit 1");
            if(empty($videoMsg))
                return $del;
            $segments = $videoMsg[0]["v_segments_list"];
            $v_uuid = $videoMsg[0]["v_uuid"];
            $oldSegmentArray = explode("\n", $segments);
            $newSegmentArray = array_filter($oldSegmentArray, function($s){
                if($s === $vsuuid)
                    return false;
                else
                    return true;
            });
            $newSegments = implode("\n", array_values($newSegmentArray));
            $updateV = db("test")->exec("UPDATE t_video SET v_segments_list = '$newSegments' WHERE v_uuid='$v_uuid'");
            return 1;
        } else
            return 0;
    } else
        return 0;
}

代码执行到if($s === $vsuuid)的时候报错如下:
Notice: Undefined variable: vsuuid in /Applications/XAMPP/xamppfiles/htdocs/waaa-web/runtime/service_Admin.php on line 1526


请问是什么原因导致的?该怎么解决呢?

array_filter($oldSegmentArray, function($s) use($vsuuid) {
    return $s !== $vsuuid;
});

顺便帮你改下下函数...

function deleteSegment($vsuuid) {
    $res = db("test")->exec("DELETE FROM t_segment_index, t_video_segment WHERE vs_uuid='$vsuuid'");
    if( !$res ) return 0;

    $videoMsg = db("test")->getQuery("SELECT * FROM `t_video` where v_segments_list like '%$vsuuid%' limit 1");
    if( empty($videoMsg) ) return 0;

    $segments = $videoMsg[0]["v_segments_list"];
    $v_uuid = $videoMsg[0]["v_uuid"];
    $oldSegmentArray = explode("\n", $segments);
    $newSegmentArray = array_filter($oldSegmentArray, function($s) use($vsuuid) { return $s !== $vsuuid; });
    $newSegments = implode("\n", array_values($newSegmentArray));

    return $updateV = db("test")->exec("UPDATE t_video SET v_segments_list = '$newSegments' WHERE v_uuid='$v_uuid'");
}

闭包(Closure) 中使用外部函数,function($param) use($otherParam){}

人气教程排行