+ 1
MYSQL!
How connect to mysql database in php?
6 Answers
+ 2
<?php
mysql_connect("localhost","root","password") or die("not connect");
mysql_select_db("database name");
?>
+ 2
try{
$bdd = new PDO('mysql:host=localhost;dbname=theName', 'root', '');
}catch(Exception $e){
die('Erreur : '.$e->getMessage());
}
the best way is to use PDO.
0
If you are using XAMPP with PHP 5.6+ then write following code
<?php
mysqli_connect("localhost:port_number","root","password","dB_name") or die("not connect" . mysqli_error());
?>
by default port number is 80
if you are connected to an other port then write port number otherwise Port no is not required.
0
<?php
$connection= mysql_connect("localhost","root","password ");
$database= mysql_connect_db("dbname," $connection);
if($database)
{
echo "connection has been created";
}
else
{
mysql_error();
}
0
in OOP you can easily, $con = new mysqli("localhost","root","","db");
because mysqli is a class and you can make it object for using it
- 3
hi just write code mysql_connect fonction snd put db username password db_name