Jump to content
  • 0
Sign in to follow this  
johnp

LAMP Tutorial does not work

Question

I have followed the tutorial on PHP /Mysql at

https://linuxhint.com/php-mysql-tutorial/

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.

 

Share this post


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.

mysql> FLUSH PRIVILEGES;

 

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.

Shovon

Share this post


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.

Guest
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.

Sign in to follow this  

×
×
  • Create New...