There's many ways to connect to a MySQL database.

But before we start, you will need the following:

  • = can be acquired from the administrator
    host name - *
    username - *
    password - *
    database name - *

After you have those, let's get started!: First, set a variable to our MySQL connection(mysql_connect), and give it values.

<?php $connection = mysql_connect("host name", "username", "password") if($connection) mysql_select_db("database name") or die("Couldn't connect to database!") echo "Connected to MySQL!" ?>

Save that file as mysql_connection.php.

Now, to explain. The first line, after the "<?php", just sets our mysql_connect() function to it so that we can use the variable to tell if it succeeds or fails.

After that, we use our if($connection) to see if the $connection variable failed or succeeded. If it did, set our database using mysqlselectdb().

NOTE: If you see "Connected to MySQL!" you followed the tutorial right!:)

Comments for this tutorial (7)

anmycat on December 31st at 9:29am

How can I connect to a MySQL database? what is the link of my Mysql database? ***.yakkel.com/(Mysql database)???

anmycat on December 31st at 10:04am

How can I connect to a MySQL database? what is the link of my Mysql database? ***.yakkel.com/(Mysql databaseurl)

786dude on January 1st at 8:55pm

You have to use like php or a programming language to "connect" to a database, there's not like a link to it.

t0m on January 1st at 9:43pm

Just follow this tutorial to connect to a MySQL database. As 786 dude said, there's no link.

t0m on December 31st at 10:36am

Just follow this tutorial to connect to a MySQL database. There is no link to an MySQL database.

52awei on January 1st at 11:12pm

How to do it!

t0m on January 2nd at 1:41pm

Just follow this tutorial. Guys, the point of tutorials is to teach you things. Just follow the steps in this and you're golden

Login or signup to comment!

Welcome!

Yakkel is your central source for web developer tutorials as well as a leading free web hosting provider.

500mb storage space
FTP access, unlimited email accounts, unlimited subdomains!

Host all your domains, for free!

learn more by taking a quick tour ›
learn about our free hosting ›
signup now ›

About this tutorial

I'll show you how to connect to a MySQL database, duh!:P

category

PHP

tagged with

mysql × 4
database × 4

published by

t0m on november 4th

viewed

418 times

comments

7 comments

Sponsored links