1

I have a database hosted on my computer using MySQL Workbench. I have a website hosted on my computer using IIS. I have created a database fennypvp and a table accounts with columns id, username and password. I have added multiple entries into the table from MySQL Workbench. Now I am simply trying to get these entries from the website with PHP. For now I'd simply like to be able to print the entries and from there I will work on validating credentials etc. I have look up quite a bit and nothing has worked for me. Here is what I've got so far:

<?php
$host="127.0.0.1";
$port=3306;
$socket="";
$user="root";
$password="";
$dbname="fennypvp";

$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
    or die ('Could not connect to the database server' . mysqli_connect_error());

$query = "select * from accounts";


if ($stmt = $con->prepare($query)) {
    $stmt->execute();
    $stmt->bind_result($field1, $field2);
    while ($stmt->fetch()) {
        printf("%s, %s\n", $field1, $field2);
    }
    $stmt->close();
}
$con->close();

?>

The above is code generated by MySQL Workbench although the page sql.php is blank. Any ideas? Here is the database and table information:

enter image description here

RicardoO
  • 27
  • 4
Jacob
  • 91
  • 2
  • 11
  • 1
    Your code probably contains errors. Have a look in your server's error log for details. – tadman Nov 02 '19 at 04:36
  • 1
    Note: Doing a `SELECT *` and then blindly binding the results is bad form. Select the specific columns you want in the order you want them. – tadman Nov 02 '19 at 04:37
  • 1
    **WARNING**: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong. Please, do not write your own authentication system when any modern [development framework](https://www.cloudways.com/blog/best-php-frameworks/) like [Laravel](http://laravel.com/) comes with a robust [authentication system](https://laravel.com/docs/master/authentication) built-in. At the absolute least follow [recommended security best practices](http://www.phptherightway.com/#security) and **never store passwords as plain-text** or a weak hash like **SHA1 or MD5**. – tadman Nov 02 '19 at 04:37
  • I can not find an error log anywhere, although I have thoroughly looked throughout my directory. I will hash the passwords once I start inputting data from the website, although for now I'm simply trying to get the data from table to website. I've done this before with no problems on a cPanel server, although I'm having trouble with the MySQL and PHP on my Windows Computer. – Jacob Nov 02 '19 at 22:54
  • Until you can find the error log you're going to be left wondering what's going wrong. When you do find the error log you'll get diagnostic data that pinpoints the problem, or at the least gives you a rough idea of what the problem is. With that we can help you. Without we can only guess. – tadman Nov 02 '19 at 23:04
  • 1
    Ok thank you. I did not find the error log although I did find a solution to the issue here: https://stackoverflow.com/questions/52364415/php-with-mysql-8-0-error-the-server-requested-authentication-method-unknown-to – Jacob Nov 03 '19 at 00:32

0 Answers0