plz help me.i am developing a webpage .i want to connect mysql database by using php .i did connection code in php. but i did't get the connection.
here i am attach what i did. if any one knows how to connect mysql database plz send the answer.
$dbhost = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$conn = mysql_connect($dbhost,$username,$password) or die ("db error");
$select_db = mysql_select_db($dbname) or die ("cloud not select db");
$db=mysql_select_db("test",$conn);
$query=mysql_query("select * from local_bus",$db);
?>
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upendra Pratap ShahiPosted Aug 3, 2015, 3:17 AM
//ENTER YOUR DATABASE CONNECTION INFO BELOW:
$hostname="db1111111111.db.1and1.com";
$database="db1111111111";
$username="dbo111111111";
$password="myPassword";
//DO NOT EDIT BELOW THIS LINE
$link = mysql_connect($hostname, $username, $password);
if (!$link) {
die('Connection failed: ' . mysql_error());
}
else{
echo "Connection to MySQL server " .$hostname . " successful!
" . PHP_EOL;
}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
die ('Can\'t select database: ' . mysql_error());
}
else {
echo 'Database ' . $database . ' successfully selected!';
}
mysql_close($link);
?>
Upendra Pratap ShahiPosted Aug 16, 2015, 3:40 AM
Sandeep KumarPosted Aug 11, 2015, 9:06 AM
}
if (!mysql_select_db("
throw new Exception("No contacts database found on database server.");