Jump to content
  • 0

LAMP Tutorial does not work


I have followed the tutorial on PHP /Mysql at


but when I create and run the dbconnection.php, and readdata.php scripts at the end of the tutorial the dbconnection script appears to work but the readdata script

gives no output. If I change the database name in dbconnection.php to a non-existent database and run the script there is no error message and in fact the

script returns the same "Connection is completed successfully" message as it does with the correct database name. Clearly there is some error in the setup

of php 7.4, I presume. I have spent several days wrestling with getting php7.4 to connect successfully to mariadb and would appreciate any advice.


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi johnp,
If you're using Ubuntu 18.04 LTS or later, you won't be able to connect to MySQL as root without superuser privileges. The solution is to create a new MySQL user and connect to MySQL using that user instead of the root user.


Steps to create a new MySQL user and database:

First, login to MySQL as root.

$ sudo mysql -u root -p


Create a new MySQL user test.

mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'secret';


Create a new database db01.

mysql> CREATE DATABASE db01;


Allow the newly created user test access to db01 database.

mysql> GRANT ALL PRIVILEGES ON db01.* TO 'test'@'localhost';


For the changes to take effect, run the following SQL statement.



Then, exit out of the MySQL console.

mysql> exit



You should be able to access MySQL database from your PHP script using the following credentials.

host = localhost

user = test

password = secret

database = db01


I hope this helps. 


Wish you all the best.


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...