You are here:

MySQL/mysql connect



I am new to php and mysql, I have got myself a hosting account and have set up a small website. I am not bad with css and html but i want to be able to use a database. I have tried all sorts of tutorials on the internet and none seem to be understandable could you put it in plain engish for me.

This is what i use to contact

//define database details
$dbhost = 'localhost';
$dbuser = 'database_user';
$dbpass = 'database_password;
$database = 'database_you_want';

//conect to database
$link = mysql_connect($dbhost, $dbuser, $dbpass);

//close database connection

The first chunk of code defines the details for your database. i would put these in an include file so that if you needed to change these it would be in one file and not on every page of your website.

the next chunk of code completes the database connection. this would go at the top of each page that required a database connection.

the last chunk of code is very important. This closes the database connection. you should put this on every page that opens a connection where the connection is no longer required. normally at the bottom of the page. This helps free up your database connections  


All Answers

Answers by Expert:

Ask Experts


stuart gregory


PHP html, xhtml, css coding and MySQL


My experiance is all first had as I am web developer and I have, and do build many websites all using php and mysql. This ranges from building a simple search engine to secure php login scripts. Some websites like are complete database driven websites.

I have a large number of websites which I host and maintain, such as.

Web application development. (Open University) BSC Honers Computing and development (Open University)

©2017 All rights reserved.

[an error occurred while processing this directive]