douyao7390 2014-11-06 22:44
浏览 48
已采纳

可以连接数据库,但没有任何反应

I have just uploaded my website to meebox (webhotel), where I have a mysql database through phpmyadmin. The database connection file is working. There is a connection but I get NO data from the database which I have stored.

Here is my php script, where I want to get some data.

The script worked on my localhost server. But I just can't find the error. Is the script too old?

            <?php

                $q = "SELECT * FROM journals ORDER BY timestamp DESC";
                $r = mysqli_query($dbc, $q);

                while($journal_list = mysqli_fetch_assoc($r)) { ?>

                <div class="col-md-6 journal-list">    
                    <a href="journalview.php?id=<?php echo $journal_list['id']; ?>">
                        <img class="journal-list-img" src="<?php echo $journal_list['image']; ´?>">
                    </a>     
                </div>


            <?php } ?>
  • 写回答

1条回答 默认 最新

  • douhan1992 2014-11-06 23:11
    关注

    You are missing the 4th parameter, DB.

    Just set a variable $db with the desired DB and try it like this:

    $servername = "localhost"; 
    $username = "xxxx"; 
    $password = "xxxx";
    $db = "database_to_use";
    
    $dbc = mysqli_connect($servername, $username, $password, $db)
    if ($dbc->connect_errno) {
        exit($dbc->connect_error);
    }
    

    unlike the old mysql_ extension where we had to do

    mysql_select_db(...)
    

    it can now be done within one line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置