简体   繁体   中英

Unable to connect to MySQL database but able to connect to database server

I am trying to build a dynamic website for connecting pages with database I used the code as follows. connection with server is Ok but unable to select database. data base name, user id, password, ip of host all gave but not working. please help....

define('DB_NAME', ''); 
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', '');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
     die('Could not connect: ' . mysql_error());
         }
else {
      echo 'connected to server..................';   }


$db_selected = mysql_select_db($DB_NAME, $link);

if ($db_selected) {

print "Database Found";

}
else {

print "Database NOT Found";

}

Mysql has been deprecated and will eventually be removed. Consider using PDO or MySqli.

Here is a link to the PHP documentation page for making connections to a database using MySqli.

http://php.net/manual/en/mysqli.quickstart.connections.php

If you follow the instructions carefully you 'should' be able to connect. If not, perhaps you can post the error message you receive.

Try to give proper credential to connect to mysql server. mysqli_connect("localhost","root","password","db_name");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM