0

I'm using wamp server for development.

Using below php code to get all db's

<?php
$txt = "Hello world!";

echo $txt;
echo "<br><br><br>";

$mysqli = new mysqli('localhost', 'root', '');
if ($mysqli->connect_errno) {
    trigger_error('query failed: '.$mysqli->connect_error, E_USER_ERROR);
}

$result = $mysqli->query('SHOW databases')
    or trigger_error('connect failed: '.join(',', $mysqli->error_list), E_USER_ERROR);

foreach( $result as $row ) {
    echo join(', ', $row), "<br />\r\n";
}

?>

Result i'm getting in browser

enter image description here

when i login to php myadmin i can see below db's

enter image description here

In Phpmyadmin: mydb and test db's are not there

IN php: testdb is not there

How can I connect test db using php ?

getting Connection failed: Unknown database 'testdb' error when i try to connect

Dharman
  • 30,962
  • 25
  • 85
  • 135
martin kumar
  • 65
  • 1
  • 2
  • 9
  • 1
    Check your port. If you are using wampserver then you might have two databases on different ports. – Dharman Jun 16 '20 at 12:22
  • 1
    You need to stop manually checking for errors. Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) and [Should I manually check for errors when calling “mysqli_stmt_prepare”?](https://stackoverflow.com/q/62216426/1839439) – Dharman Jun 16 '20 at 12:23

0 Answers0