Connect to mysql database

This is not really a challenging problem, but (I at least) always forget the exact syntax and have to copy-paste it from somewhere else.

Generally, when building a PHP site, at some point you want to connect at the database. Here you find the code I use for this:

$dbhost = 'localhost';
$dbuser = 'root';
$dbpassword = 'password';
//do the connection
$conn = mysql_connect($dbhost, $dbuser, $dbpassword)
or die  ('Error connecting to mysql');
//open a specific database
$dbname = 'myDatabase';
mysql_select_db($dbname, $conn);


Search RSS
Only registered users can write comments!

3.23 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."