使用mamp显示mysql数据库中的图像

fnvucqvd  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(301)

这个问题在这里已经有答案了

php代码没有被执行,而是显示在页面上的代码(28个答案)
警告:mysqli\u select\u db()只需要2个参数,1个参数在c:[duplicate](1个答案)中给出
两年前关门了。
我正在尝试通过macos上的mamp从mysql数据库查询图像。
我使用的代码是:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, intial-scale=1.0"/> -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>Show Image in PHP</title>
<style>
    body{background-color: #f2f2f2; color: #333;}
    .main{box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; margin-top: 10px;}
    h3{background-color: #4294D1; color: #f7f7f7; padding: 15px; border-radius: 4px; box-shadow: 0 1px 6px rgba(57,73,76,0.35);}
    .img-box{margin-top: 20px;}
    .img-block{float: left; margin-right: 5px; text-align: center;}
    p{margin-top: 0;}
    img{width: 375px; min-height: 250px; margin-bottom: 10px; box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; border:6px solid #f7f7f7;}
</style>
</head>
    <body>
    <!-------------------Main Content------------------------------>
    <div class="container main">
        <h3>Showing Images</h3>
        <div class="img-box">
    <?php

        $username="root"; $password="root"; $database="SomeImages";

        $con = mysqli_init();
        mysqli_options($con, MYSQLI_OPT_LOCAL_INFILE, true);
        mysqli_real_connect($con, "localhost", $username, $password, $database);

        mysqli_select_db($database);

        $image_query = mysqli_query($con, "SELECT framing,im FROM images");

        while($rows = mysqli_fetch_array($image_query))
        {
            $img_name = $rows['framing'];
            $img_src = $rows['im'];
        ?>

        <div class="img-block">
        <img src="<?php echo $img_src; ?>" alt="" title="<?php echo $img_name; ?>" width="300" height="200" class="img-responsive" />
        <p><strong><?php echo $img_name; ?></strong></p>
        </div>

        <?php
        }
    ?>
        </div>
    </div>
    </body>
</body>
</html>

当我从我的ide(coderunner)中“运行”它时,我在控制台中得到完全实用的html(没有错误消息),如下所示:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, intial-scale=1.0"/> -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>Show Image in PHP - Campuslife</title>
<style>
    body{background-color: #f2f2f2; color: #333;}
    .main{box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; margin-top: 10px;}
    h3{background-color: #4294D1; color: #f7f7f7; padding: 15px; border-radius: 4px; box-shadow: 0 1px 6px rgba(57,73,76,0.35);}
    .img-box{margin-top: 20px;}
    .img-block{float: left; margin-right: 5px; text-align: center;}
    p{margin-top: 0;}
    img{width: 375px; min-height: 250px; margin-bottom: 10px; box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; border:6px solid #f7f7f7;}
</style>
</head>
    <body>
    <!-------------------Main Content------------------------------>
    <div class="container main">
        <h3>Showing Images from database</h3>
        <div class="img-box">

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in index.html on line 31

        <div class="img-block">
        <img src="images/0.jpg" alt="" title="3" width="300" height="200" class="img-responsive" />
        <p><strong>3</strong></p>
        </div>

        <div class="img-block">
        <img src="images/2.jpg" alt="" title="3" width="300" height="200" class="img-responsive" />
        <p><strong>3</strong></p>
        </div>

        <div class="img-block">
        <img src="images/2.jpg" alt="" title="3" width="300" height="200" class="img-responsive" />
        <p><strong>3</strong></p>
        </div>
</div>
    </div>
    </body>
</body>
</html>

但是,当我用http://localhost:8888/someimages/,我得到了这个,其中的php部分评论:

我做错什么了?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题