Hello,
Im unable to connect database please anybody help me
<?php
$host = "localhost"; // db host
$user = "username"; // db username
$pass = "password"; // db password
$db = "dbname"; // db name
$conn = mysql_connect("$host", "$user", "$pass", "$db") ;
mysql_select_db($db);
?>
i saved this on config.php and called this file in another file in below format
<?php
include("config.php");
?>
Please any body help me.
Regards,
Saleem
Database is not connect
Moderator: General Moderators
Re: Database is not connect
First, I would suggest you to use mysqli_ functions instead of mysql_, as mysql_ functions are deprecated in latest PHP version.
Regarding your issue:
You have used database name as fourth parameter to mysql_connect() function which is not valid
check the manual for the same: http://php.net/manual/en/function.mysql-connect.php
Use mysql_error() to check the database connection errors or use this connection code
may this will help you
Regarding your issue:
You have used database name as fourth parameter to mysql_connect() function which is not valid
check the manual for the same: http://php.net/manual/en/function.mysql-connect.php
Use mysql_error() to check the database connection errors or use this connection code
Code: Select all
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>-
rushikant123
- Forum Newbie
- Posts: 3
- Joined: Fri Jul 18, 2014 8:40 am
Re: Database is not connect
<?php
// for hosting server-->
// $con=mysqli_connect("localhost","studiom_rushi","rushi123","studiom_Messages");
// for localhost-->
$con=mysqli_connect("localhost","root","","Details");
if (mysqli_connect_errno())
{
echo "MySql Connection failed:" . mysqli_connect_error();
}
?>
// for hosting server-->
// $con=mysqli_connect("localhost","studiom_rushi","rushi123","studiom_Messages");
// for localhost-->
$con=mysqli_connect("localhost","root","","Details");
if (mysqli_connect_errno())
{
echo "MySql Connection failed:" . mysqli_connect_error();
}
?>