Pages with mysql won't load

Username (epiz_32975619) and Website URL
http://stengrade.great-site.net/index.php

Error Message

None at all, it just does not work.

Other Information
All pages in my website with a mysql connection don’t load, only the navbar added with an include does. The weirdest part is that my site works perfectly on my own computer’s local server.
Any help would be greatly appreciated.
Here is my code for one of the pages incase I messed something up.

<?php
include "nav.php";
$db = new PDO("mysql:host = ; dbname= ", "   ", "   ");
$query = $db->prepare("SELECT * FROM monster");
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);



?>
<body>
<div class="bg-primary bg-opacity-10">
    <div class="container-lg bg-primary bg-opacity-10" style="min-height: 62%">
        <br><br>
        <div class="row">

            <?php
            foreach ($result as $data) {
                echo "<div class='col'>";
                echo "<div class='card bg-danger' style='max-width: 150px;'>";
                echo "<img class='img-fluid img-thumbnail bg-danger ' style ='max-height:150px;' src='" .$data['img'] ."'>";
                echo "<div class='card-body'>";
                echo "<b>" . $data['name'] . "</b><br>";
                echo "<i class='bi bi-emoji-dizzy'></i> : " . $data['number'];
                echo "    </div>";
                echo "</div>";
                echo "</div>";
            }

            
            ?>
        </div>
        <br>
    </div>

</div>
<?php include "footer.php"; ?>
</body>

Yes, I can see it perfectly too:


This means that you haven’t cleared your cache on the computer that’s giving you the error message.
You can find the shortcut to clear your cache here.

4 Likes

Forgot to mention, Index does not use mysql, a page that does is ‘kill sheet’ that is where the code is from.

What are you trying to do here?

2 Likes

I removed it for this post, in the actual code I have: database name, username and password

Enable display_errors by logging into your control panel > alter PHP config

4 Likes

Thanks, now the error message I am getting are:

Connection failed: SQLSTATE[HY000] [2002] No such file or directory

Warning : Invalid argument supplied for foreach() in**/home/vol8_8/epizy.com/epiz_32975619/htdocs/kills.php** on line22

I understand that the connection with the database does not work, but whatever I do I can’t fix it.

This may help

4 Likes

Please note that the MySQL connection string is sensitive to whitespace. So if you use mysql:host = sql123.epizy.com or mysql:host=sql123.epizy.com, those actually mean different things.

So what I think is happening is that your connection string is being ignored entirely and you’re connecting with all default values. This is usually hostname localhost with username root and no password. On your own computer, these default settings also work and so does the site, but on our hosting the issue becomes apparent.

Please try removing all the spaces from the connection string. If the provided parameters are correct, it should solve the issue.

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.