welcome to Beerwin's Blog !

This blog has been started because there are many things that cannot be placed on the main site, but they are such good things, that they cannot be omitted. See them here.

Terms and conditions

Anyone can use any posts from my blog (except comments) with the following conditions:

  • Backlink
  • The material will not be sold
  • The material will not be used for marketing purposes
  • Multilevel Web Marketers: GO AWAY!

Connecting to a MySQL database with PHP

Filed Under (PHP) by beerwin on 04-05-2008

Tagged Under : ,

In this tutorial, i will tell, how to connect to an existing MySQL database with an existing username and password.

For the first, we need the database and the credentials for it. If you are using a free web hosting service with PHP and MySQL support, you already have this information.

If you have a web server installed with PHP and MySQL, you have to create a database and a username. Since this is not part of this tutorial i will talk about it in another post.

Now, it’s time to get connected. We will create the db.inc.php file:

1
2
3
4
5
6
7
8
9
10
11
12
13
//database connection file// for first, we need to set database name, host, username and password for our connection. Modify them corresponding to your data.

$dbhost
=“localhost”;
$dbusername
=”your_username”;
$dbpassword
=“yourpassword”;
$db
=“your_db”;

//If you filled in your data, it’s time to make the connection. Don’t modify anything below this line

$connector = mysql_connect($dbhost, $dbusername, $password) or die(Could not connect to MySQL!);

$db = mysql_select_db($db, $connector) or die(“Couldn’t select database.”);

Beerwin’s blog

Filed Under (General) by beerwin on 04-05-2008

Tagged Under : , ,

You will get HTML, CSS, PHP and some Javascript tutorials, Things about PlainHTML developement (We will watch under the hood).

Subscribe to Rss Feed : Rss