My boss asked me to see if it was possible to generate an HTML table based on SQL data via the company's WordPress site. I'm not super-familiar with PHP or SQL, but I saw that others had been able to do it.
The problem is, after spending a full week on it, I can't seem to pull anything from the server. I've tried dozens of times, but nothing has worked. Every time I tried to connect to the server, it seemed to go through fine, but when I tried a basic query (that was already working in the MySQL workbench), it could never pull any results in.
Today, I did a test that may have solved the issue: I was able to connect to the server, but when I asked for the code to check which database it connected to, it came up blank.
The code:
<?php
$conn = mysqli_connect("IP address", 3306, "socket", "user", "pw");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else {
echo "Connection active.<br><br>"; }
mysqli_select_db($conn, "dbname")
or die('Could not select a database.');
?>
And the result is:
Connection active.
Could not select a database.
This code is based on the PHP.net manual, but I've tried a bunch of different variations and they haven't had any luck, either. I have tried using the dbname
inside of the $conn
variable, but that didn't seem to do anything, either.
If it wasn't already clear, I'm a super-beginner at this and have no idea what I'm doing wrong. I've handled plenty of other site coding issues in the past, and I really don't want this to be the one to defeat me - if anyone out there can help, I'd be eternally grateful.