Audel
Audel

Reputation: 2509

Making a local connection between a mysql database and php

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

Upvotes: 5

Views: 16956

Answers (3)

streetparade
streetparade

Reputation: 32888

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";
?>

Upvotes: 1

casraf
casraf

Reputation: 21694

$server = 'localhost';
$user = 'myUser';
$pass = 'myPass';
$dbname = 'MyDatabase';
$con = mysql_connect($server, $user, $pass) or die("Can't connect");
mysql_select_db($dbname);

Upvotes: 6

Dominik
Dominik

Reputation: 1202

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

Upvotes: 1

Related Questions