[英]“object not found” while connecting to mysql database with php
I have created my database "MUSIC" in phpmyadmin in xampp. 我在xampp的phpmyadmin中创建了数据库“ MUSIC”。 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:
我正在尝试使用存储在OML文件夹中的php文件连接到该数据库,该文件又位于htdocs文件夹中,我的代码是:
$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: 但是当我转到localhost并键入
localhost/connect.php
,出现此错误:
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! 我已经搜索过,但是找到了解决此问题的方法,请帮忙!
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
我正在尝试使用存储在OML文件夹中的php文件连接到该数据库,该文件又位于htdocs文件夹中
So, the URI would be /OML/connect.php
instead of just /connect.php
, right? 因此,URI将是
/OML/connect.php
而不是/connect.php
,对吧?
尝试在地址栏中输入以下内容:“ localhost / OML / connect.php”
$connect = mysqli_connect("localhost","root","ash123","MUSIC");
Replace this code in database connection file . 在数据库连接文件中替换此代码。 Remove the codes you shown .
删除您显示的代码。
mysql_connect()
is deprecated , and you improperly select the database. 不建议使用
mysql_connect()
,并且选择了不正确的数据库。
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. 此时建立连接,并选择数据库。
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();
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.