1

I'm having a problem connecting to my external DB.

    <?php
        $db = new mysqli('mysql1.myregisteredsite.com', 'USERNAME', 'PASSWORD', '34928_Test2');
        $sql = "SELECT * FROM Contacts";
        $result = $db->query($sql);

        if($db->connect_errno > 0){
            die('Unable to connect to database: [' . $db->connect_error . ']');
        }

    ?><!DOCTYPE html>
    <html>
        <head>
            <title>SELECT Example</title>
        </head>
        <body>
            <div id="wrapper">
                <h1>Contacts from Our Contacts Table</h1>
                <ul>
                     <? while ($row = $result->fetch_assoc()): ?>
                         <li><?= $row['First_Name'] ?></li>
                         <li><?= $row['Middle_Name'] ?></li>
                         <li><?= $row['Last_Name'] ?></li>
                     <? endwhile; ?>
                </ul>

            </div>    
        </body>
    </html>

Something is wrong, because it doesn't show anything. When it upload it to the server and try it, the page is completely blank. I've tried connecting using PDO, declaring with XHTML 1.0 Strict instead of HTML 5, both with the same result of a blank page.

When I try running it locally I get this error:

Warning: mysqli::mysqli(): (HY000/2000): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file in C:\xampp\htdocs\DBTest\index.php on line 2

I've tried creating a new user/password, which still results in the same message. I've called my domain registrar or whatever they're called and using the credentials in my index.php file they were able to connect to the database, so they said it was something to do with how my code was written but aren't able to help me in that retrospect.

It's just a simple connect statement, why won't it work?

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
Logue1021
  • 54
  • 8
  • Do you know which version of MySQL is installed on that server? Because the way you connect looks okay and the error message indicates that something _very very not good (TM)_ is going on with your hosting provider (that's what they're called). – Carsten Mar 28 '14 at 22:31
  • @tlenss I came across that in my research, but as how do I restart MySQL or run the SELECT user statement on a remote server? – Logue1021 Mar 28 '14 at 22:45
  • @Carsten I called my hosting provider, and they're running MySQL 5. – Logue1021 Mar 28 '14 at 23:00

0 Answers0