我正在尝试通过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/从浏览器中打开html / php代码时,我得到了,其中的php部分带有注释:
我在做什么错了?