我无法使用这组代码访问数据库。同时使用 PDO 和另一种方法,他们不访问 config.php

<body>

    <h1> helloo </h1>

    <div class="gallery">

    <?php 

    // Include database configuration file 

    require 'dbConfig.php'; 


    // Retrieve images from the database 

    $query = $DB->query("SELECT * FROM /phpgallery/images WHERE status = 1 ORDER BY uploaded_date DESC"); 


    if($query->num_rows > 0){ 

        while($row = $query->fetch_assoc()){ 

            $imageThumbURL = 'images/'.$row["file_name"]; 

            $imageURL = 'images/'.$row["file_name"]; 

    ?>

        <a href="<?php echo $imageURL; ?>" data-fancybox="gallery" data-caption="<?php echo $row["title"]; ?>" >

            <img src="<?php echo $imageThumbURL; ?>" alt="" />

        </a>

    <?php } 

    } ?>

</div>

</body>

<body>

    <h1> helloo </h1>

    <div class="gallery">

    <?php 

    // Include database configuration file 

    require 'dbConfig.php'; 


    // Retrieve images from the database 

    $query = $DB->query("SELECT * FROM /phpgallery/images WHERE status = 1 ORDER BY uploaded_date DESC"); 


    if($query->num_rows > 0){ 

        while($row = $query->fetch_assoc()){ 

            $imageThumbURL = 'images/'.$row["file_name"]; 

            $imageURL = 'images/'.$row["file_name"]; 

    ?>

        <a href="<?php echo $imageURL; ?>" data-fancybox="gallery" data-caption="<?php echo $row["title"]; ?>" >

            <img src="<?php echo $imageThumbURL; ?>" alt="" />

        </a>

    <?php } 

    } ?>

</div>

</body>

这两个文件在同一个文件夹中,但数据库在另一个文件夹中。


E:\Xampp\htdocs\phpgallery\images <- 存储数据库的图像。E:\Xampp\htdocs\dynamicImageGallery <- 我从哪里运行代码。


慕少森
浏览 164回答 1
1回答

至尊宝的传说

如果您使用的是 MySQL,您似乎正在调用一个您应该调用表名的目录。例如,如果您将图像存储在名为 tbl_images 的表中,则需要使用表名而不是数据库或图像存储目录的查询。tbl_images| id | file_name&nbsp; &nbsp;||----|-------------|| 1&nbsp; | image01.jpg |索引.php$query = $DB->query("SELECT * FROM tbl_images WHERE status = 1 ORDER BY uploaded_date DESC");&nbsp;希望这能解决您的问题。
打开App,查看更多内容
随时随地看视频慕课网APP