How to connect from MySQL to Web Application [duplicate]

I have been trying to setup a local instance for a web application.

I am new to MySQL and I can't understand how to actually connect this database to the actual web application sitting in the /var/www folder in my computer.

I have created a database in command line terminal:

mysql> create database mydatabase
-> ;
Query OK, 1 row affected (0.00 sec)
mysql> create user 'host'@'website.local' identified by 'hmypassword';
Query OK, 0 rows affected (0.00 sec)
mysql> create user 'host'@'%' identified by 'mypassword';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on database.* to 'host'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
mysql -u host -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)

How do I actually connect this database to the website? I also don't understand how to make a schema for this databse.

Whenever I try to refresh my web browser I get the following message:

Could not access database!
SQLSTATE[HY000] [2002] Connection refused
2

1 Answer

The basic mechanism is:

  • the browser asks the web server for a web page. This is in fact the address of a program or script, most often written in PHP.
  • the web server executes the PHP program.
  • the PHP program accesses the data base server using SQL statements.
  • the data base server returns data to the program.
  • the program puts the data into an HTML page.
  • the web server sends the HTML page to the browser.

So you still have some way to go. Please take a look at stackoverflow to find examples of the above.

You Might Also Like