如何在 php 中插入和下载任何文件到 sql server? [关闭]

问题描述 投票:0回答:0

我已经成功地使用mysql插入和下载数据,然后我想将它迁移到sql server / ms sql,但结果与我尝试使用mysql完全不同,sql server在mysql中使用varbinary而不是blob,它还将数据存储在您的计算机内部。我不知道如何用 sql server 来做。我在互联网上搜索,除了如何使用 mysql 之外什么也没找到。我该怎么做?

我用mysql试过这段代码

if (isset($_GET['file_id'])) {
    $id = $_GET['file_id'];

    // fetch file to download from database
    $sql = "SELECT * FROM users WHERE id=$id";
    $result = mysqli_query($conn, $sql);

    $file = mysqli_fetch_assoc($result);
    $filepath = 'uploads/' . $file['file'];

    if (file_exists($filepath)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . basename($filepath));
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize('uploads/' . $file['file']));

        //This part of code prevents files from being corrupted after download
        ob_clean();
        flush();

        readfile('uploads/' . $file['file']);

        // Now update downloads count
        mysqli_query($conn, $updateQuery);
        exit;
    }

}

对不起我的英语不好,我不是很擅长。

php sql-server download sql-insert
© www.soinside.com 2019 - 2024. All rights reserved.