Topic: [Tutorial] How to connect to MYSQL Database

It is very simple to connect to a mysql database:

just use this simple code:

<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("database") or die(mysql_error());
echo "Connected to Database";
?>

Thumbs up

Re: [Tutorial] How to connect to MYSQL Database

And for something more usefull, to use it as a function so you can call it when you need it.

function db_connect() {
$connect = mysql_connect("localhost", "username", "password", );
if(!mysql_select_db("database"))
   {
      return false;
   } else {
      return $connect;
   }
}

Thumbs up

Re: [Tutorial] How to connect to MYSQL Database

Hello friends,

please can you provide idiot-proof step by step information about how set up a MySQL database on my pc which is also accessible from afar?

This could also work for others as a tutorial(and probably broaden our community).

I already have problem downloading the proper files from sunmicro nor do I know what to do with them as they are no exe or batch files.

Last edited by Reginald (October 2, 2010 05:34)

Thumbs up

Re: [Tutorial] How to connect to MYSQL Database

Very useful for me.. Thanks for sharing this function..

Thumbs up