5

I already have the mysql database made, I just need to connect php to mysql locally but I don't know the php commands for that.

cheers

Audel
  • 2,479
  • 5
  • 24
  • 20
  • The only thing I just need to find the names of my localhost and of my username, how can i find those? – Audel Feb 25 '10 at 14:28

3 Answers3

6
$server = 'localhost';
$user = 'myUser';
$pass = 'myPass';
$dbname = 'MyDatabase';
$con = mysql_connect($server, $user, $pass) or die("Can't connect");
mysql_select_db($dbname);
casraf
  • 21,085
  • 9
  • 56
  • 91
  • yes, I understand that, what i can't find are the localhost and user names. when i log into mysql it just asks me for the password – Audel Feb 25 '10 at 14:26
  • 1
    Your server installation or docs should tell you that -- the host is most likely `localhost`, though not 100% of the times; as for the username, if you haven't defined it, try `root` or something global you use around your server, – casraf Feb 25 '10 at 14:36
1

The following contains a pretty good example: http://ca3.php.net/manual/en/mysql.examples-basic.php

Dominik
  • 1,194
  • 6
  • 9
1

This is a simple connect to the mysql server. After Connecting to the server it selects a DB

<?php
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";
?>
streetparade
  • 32,000
  • 37
  • 101
  • 123