简体   繁体   中英

Connect to XAMPP MySQL Database from Document Root on another Drive

would like to ask about configuration of XAMPP mySQL database.

I have set my xampp document root to drive D, and now i unable to connect to SQL database and always get error.

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in D:\localserver\connection.php:3 Stack trace: #0 D:\localserver\login.php(4): include() #1 {main} thrown in D:\localserver\connection.php on line 3

the file that handle the connection look like this

<?php 
$connect = mysql_connect("localhost","root","");
  if(!$connect) {
    die ('connection fail!!!');
  } else {
    print ('connection okay!!!');
  }
$connectdb = mysql_select_db('admin_login');
  if(!$connectdb) {
    die ('connection fail!!!');
  } else {
    print ('connection okay!!!');
  }
?>  

The mysql_connect() function is from a library that is deprecated since a couple of years and has been removed in PHP 7.

Use mysqli_connect() or PDO.

UPDATE

You can pass the name of the database into mysqli_connect() and get rid of the extra mysqli_select_db() . If you want to user mysqli_select_db() in procedural style instead of object oriented it expects the link that is returned by mysqli_connect() as the first parameter and the database name as the second one like this:

$link = mysqli_connect("localhost", $user, $password);
$db = mysqli_select_db($link, $dbname);

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