I'm new to php and have been trying to display my mysql database table onto a webpage. I've been working through the w3schools tutorial but can't get past this select data part (the reason I'm asking is not because of a tutorial but because I'm working on an assignment for class).
The connection works well but then the query always returns NULL. The query used to be more specific but now I'm just trying to get anything to display.
In mysql:
describe members
returns
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| Name | varchar(30) | YES | | NULL | |
| Type | varchar(20) | YES | | NULL | |
| State | char(2) | YES | | NULL | |
| Price | int(11) | YES | | NULL | |
| Experience | int(11) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
-
select * from members;
returns (obviously not showing 20k rows):
20000 rows in set (0.05 sec)
In PHP:
<?php
$conn = mysql_connect("127.0.0.1:3306", "root", "NotPostingOnSO", "coaches");
if(!$conn) {
die("Connection failed");
}
$result = mysql_query($conn, "SELECT Name FROM members");
echo "vardump is: <br>";
var_dump($result);
mysql_close($conn);
?>
vardump returns NULL no matter what I do...
Note: I know about mysql_* and its deprecation but when I use mysqli_connect the connection fails...this website won't even be up in a week, I just need help with getting my database to appear as a table in php (end goal)
See vardump at http://45.55.175.147/findCoach.php which shows the error being Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1' at line 1
stack is Ubuntu 14.04, Apache2, PHP from instructions on digitalocean startup and same for mysql
UPDATE:
I changed mysql_connect to mysqli_connect as:
$conn = mysqli_connect("127.0.0.1:3306", "root", "Hydro1$", "coaches");
if(!$conn) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
This returns error:
Error: Unable to connect to MySQL. Debugging errno: 2005 Debugging error: Unknown MySQL server host '127.0.0.1:3306' (11)
Update using mysql (not mysqli) Reverted to mysql_connect and fixed syntax so query is;
$result = mysql_query("SELECT Name FROM members");
vardump now returns bool(false); I feel like this is closer, but doesn't bool(false) imply the table members has no rows?