+ 1

MYSQL!

How connect to mysql database in php?

13th Jun 2016, 5:03 PM
#Bargas
#Bargas - avatar
6 Answers
+ 2
<?php mysql_connect("localhost","root","password") or die("not connect"); mysql_select_db("database name"); ?>
13th Jun 2016, 11:59 PM
usama shafi
usama shafi - avatar
+ 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.
14th Jun 2016, 10:29 AM
Claudiu Cirtina
Claudiu Cirtina - avatar
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.
14th Jun 2016, 2:57 PM
Uni Web Tech
Uni Web Tech - avatar
0
<?php $connection= mysql_connect("localhost","root","password "); $database= mysql_connect_db("dbname," $connection); if($database) { echo "connection has been created"; } else { mysql_error(); }
21st Jun 2016, 3:16 PM
Tayyaba Butt
Tayyaba Butt - avatar
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
25th Jun 2016, 9:20 AM
Rafsan Jani
Rafsan Jani - avatar
- 3
hi just write code mysql_connect fonction snd put db username password db_name
13th Jun 2016, 6:32 PM
Narasimha Javvaji
Narasimha Javvaji - avatar