Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

读取数据库中的图片出现了问题,报mysqli_result::fetchAll()错误,网上没找到相关,该怎么修改?

html:

<form method="post" action="upimage.php" enctype="multipart/form-data">
    描述:
    <input type="text" name="form_description" size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>
    上传文件到数据库:
    <input type="file" name="form_data" size="40"><br>
    <input type="submit" name="submit" value="提交">
</form>

upimage.php:

<?php
if (isset($_POST['submit'])) {
    $form_description = $_POST['form_description'];
    $form_data_name = $_FILES['form_data']['name'];
    $form_data_size = $_FILES['form_data']['size'];
    $form_data_type = $_FILES['form_data']['type'];
    $form_data = $_FILES['form_data']['tmp_name'];
    
    $conn = mysqli_connect('localhost', 'root', 'root', 'upload', '8080');
    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
    //echo "mysqlPicture=".$data;
    
    $result = $conn->query("INSERT INTO ccs_image (description,bin_data,filename,filesize,filetype)
                  VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
    if ($result) {
        echo "图片已存储到数据库";
    } else {
        echo "请求失败,请重试";
    }
}

getimage:

<?php
    $id =2;// $_GET['id']; 为简洁,直接将id写上了,正常应该是通过用户填入的id获取的
    $conn = mysqli_connect('localhost', 'root', 'root', 'upload', '8080');
    $query = "select bin_data,filetype from ccs_image where id=2";
    $result = $conn->query($query);
    $result = $result->fetchAll(2);
    //var_dump($result);
    $data = $result[0]['bin_data'];
    $type = $result[0]['filetype'];
    Header( "Content-type: $type");
    echo $data;
?>

在网上找的相关教程,然后根据自己的修改,可以上传图片保存到数据库中,但是读取数据库里的图片出现了问题,报
Fatal error: Call to undefined method mysqli_result::fetchAll() in E:BoboCodeuploadUploadImagegetimage.php on line 6
错误,是getimage里这个$result = $result->fetchAll(2);,原代码用的是PDO连接数据库,我用了连接不上,就换成了mysqli,然后获取图片的php就报错了,网上没搜到相关,这个该怎么修改?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

大哥,你是认真的吗?? **Fatal error**: Call to undefined method mysqli_result::fetchAll() 这么详细的错误,你在搜索什么啊?但凡你用的 IDE 自动补全功能正常,但凡你去看下文档... 都能看到,mysqli_result下的这个方法名是 fetch_all()

https://www.php.net/manual/zh/mysqli-result.fetch-all.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...