Unknown database 'database_name' in MySQL with WAMPServer

16,144

Not exactly an answer to your question but too long for a comment:
After establishing the database connection you could just query the existing databases via SHOW DATABASES

<?php
$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";
}

Does your database als show up?
Since you're using the default root account (with an empty password; you might want to look into that as well) there shouldn't be any permission related problems. So, if the database doesn't show up, it's just not there...

(almost) same script using PDO (my weapon of choice) instead of mysqli:

<?php
$pdo = new PDO('mysql:host=localhost;charset=utf8', 'root', '', array(
    PDO::MYSQL_ATTR_DIRECT_QUERY => false,
    PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION
));

foreach( $pdo->query('SHOW DATABASES', PDO::FETCH_NUM) as $row ) {
    echo $row[0], "<br />\r\n";
}
Share:
16,144
Melvin Jay Belenario
Author by

Melvin Jay Belenario

Updated on June 04, 2022

Comments

  • Melvin Jay Belenario
    Melvin Jay Belenario about 2 years

    I already have my database named als and I still got the error.

    <?php
    
    $mysql_host='localhost';
    $mysql_user='root';
    $mysql_password='';
    $mysql_db='als';
    $con = @mysql_connect($mysql_host,$mysql_user,$mysql_password) or             die(mysql_error());
    @mysql_select_db($mysql_db) or die(mysql_error());
    
    ?>