Reputation: 21
I have created my database "MUSIC" in phpmyadmin in xampp. I am trying to connect to this database using a php file which i have stored in the OML folder which in turn is present in the htdocs folder my code is:
$db_name="MUSIC";
$db_user="root";
$db_pwd="ash123";
$db_host="localhost";
$connect = mysql_connect("localhost","root","ash123");
mysql_select_db("MUSIC");
echo "connection successful";
but when I go to localhost and type localhost/connect.php
, I get this error:
Object not found!
the requested URL was not found on this server.if u entered the URL manually please check your spelling and try again.If you think this is a server error,please contact webmaster.
Error 404
localhost
Apache/2.4.3 (Unix) OpenSSL/1.0.1c PHP/5.4.7
I have searched but I have found a solution to this problem, please help!
Upvotes: 2
Views: 4696
Reputation: 1
Please try this to connect to your data base
<?php
$connect = mysqli_connect("localhost", "root", "ash123", "MUSIC");
if(mysqli_connect_errno())
{
echo "Warning ERROR while connection DataBase." .mysqli_connect_errno();
}
?>
Upvotes: 0
Reputation: 4972
mysql_connect()
is deprecated, and you improperly select the database.
Your code should be:
$db_name="MUSIC";
$db_user="root";
$db_pwd="ash123";
$db_host="localhost";
$link = mysqli_connect($db_host, $db_pwd, $db_name);
if (!$link->connect_error) {
echo "connection successful";
} else {
echo $link->connect_error
}
At that point the connection is established, and the DB is selected.
Upvotes: 0
Reputation: 1
$connect = mysqli_connect("localhost","root","ash123","MUSIC");
Replace this code in database connection file . Remove the codes you shown .
Upvotes: 0
Reputation: 122
Try typing this in the address bar: "localhost/OML/connect.php"
Upvotes: 0
Reputation: 95335
i am trying to connect to this database using a php file which i have stored in the OML folder which in turn is present in the htdocs folder
So, the URI would be /OML/connect.php
instead of just /connect.php
, right?
Upvotes: 1