-1

I have two databases on mysql server 'application' and 'test'. I am trying to connect to 'application' db using the following code

<?php
$link = mysqli_connect('127.0.0.1:3360','root','','application');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
?>

This is giving me the following error:

Warning: mysqli_connect(): (HY000/1049): Unknown database 'application' in C:\xampp\htdocs\ServerScripting.php on line 2

Fatal error: Uncaught Error: Call to undefined function mysql_error() in C:\xampp\htdocs\ServerScripting.php:4 Stack trace: #0 {main} thrown in C:\xampp\htdocs\ServerScripting.php on line 4

Whereas when I tried to connect to 'test' database it worked giving:

Connected successfully

I am using XAMPP server. I checked the permissions for each database and all the users are granted with complete access. I don't understand why this is happening.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Raviteja Reddy
  • 109
  • 2
  • 14

2 Answers2

1

You're using the wrong port number. It should be 3306 instead of 3360.

Karlo Kokkak
  • 3,674
  • 4
  • 18
  • 33
-1

The XAMPP server's mysql db is running on port 3360 whereas mySQL command line client is on port 3306. So the 'test' db is on port 3360 and 'application' db is on 3306. As testing I queried all the databases available on the server and so came to know the reason behind the error I am facing.

<?php
   $link = mysqli_connect('127.0.0.1:3360','root','');
   if (!$link) {
       die('Could not connect: ' . mysqli_error());
   }
   echo 'Connected successfully';
   $result = mysqli_query($link , "SHOW DATABASES;");
   while ($row = mysqli_fetch_array($result)) {        
       echo $row[0]."<br>";        
   }
?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Raviteja Reddy
  • 109
  • 2
  • 14