have been having some trouble displaying information from my database in the online IDE cloud 9. I have followed some guides about connecting to databases and retrieving information, but it doesn't seem to enter the while loop that actually echo's the information to the browser.
PHP
$host = getenv("REMOTE_ADDR");
$username = "tannerhallman1";
$password = "";
$database = "Charlotte";
$dbport = 3306;
// Create connection
$db = mysqli_connect($host, $username, $password, $database, $dbport);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
echo "Connected successfully my dude(".$db->host_info.")";
?>
<?php
$sql = "SELECT * FROM lenders";
$records = mysql_query($sql);
echo "$records"
?>
<html>
<head>
<title>Local Lenders</title>
</head>
<body>
<table width = "600" border = "1" cellpadding="1" cellspacing = "1">
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Company</th>
<tr>
<?php
while ($lender = mysql_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$lender['ID']."</td";
echo "<td>".$lender['First']."</td>";
echo "<td>".$lender['Last']."</td>";
echo "<td>".$lender['Company']."</td>";
echo "</tr>";
} //end while
?>
</table>
</body>
</html>
Server console
==> /home/ubuntu/lib/apache2/log/error.log <==
[Mon Mar 23 13:59:17.146489 2015] [:error] [pid 26008] [client 10.240.52.53:54254] PHP Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on '10.240.52.53' (111) in /home/ubuntu/workspace/lenders.php on line 13
[Mon Mar 23 13:59:17.146571 2015] [:error] [pid 26008] [client 10.240.52.53:54254] PHP Notice: Trying to get property of non-object in /home/ubuntu/workspace/lenders.php on line 16
[Mon Mar 23 13:59:17.146580 2015] [:error] [pid 26008] [client 10.240.52.53:54254] PHP Notice: Trying to get property of non-object in /home/ubuntu/workspace/lenders.php on line 19
[Mon Mar 23 13:59:17.146680 2015] [:error] [pid 26008] [client 10.240.52.53:54254] PHP Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/ubuntu/workspace/lenders.php on line 24
[Mon Mar 23 13:59:17.146693 2015] [:error] [pid 26008] [client 10.240.52.53:54254] PHP Warning: mysql_query(): A link to the server could not be established in /home/ubuntu/workspace/lenders.php on line 24
[Mon Mar 23 13:59:17.146708 2015] [:error] [pid 26008] [client 10.240.52.53:54254] PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/ubuntu/workspace/lenders.php on line 48
C9 Terminal output
mysql> select * FROM lenders;
+----+--------+---------+--------------+-----------+-------------------------------------------------------+
| ID | First | Last | Company | Phone | Bio |
+----+--------+---------+--------------+-----------+-------------------------------------------------------+
| 1 | Tanner | Hallman | UNCW | 123456789 | I am a cool guy that would be good for your finances. |
| 2 | Wes | Hallman | Mortgage Pro | 987654321 | I'm a good, cool person. |
+----+--------+---------+--------------+-----------+-------------------------------------------------------+
2 rows in set (0.00 sec)
Output from Browser I get the start of a table, with the headers but it doesn't retrieve the data. I have confirmed that c9 can actually connect to the database using the c9 terminal, so I am lost.
Connected successfully my dude()
ID | First Name | Last Name | Company