数据库已创建,但作为未知数据库返回错误 [英] Database is created but return error as unknown database

查看:46
本文介绍了数据库已创建,但作为未知数据库返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了数据库,并且已经准备好将PHP中的页面连接到数据库.我的连接代码如下:

I already have created my database, and already have the pages in PHP ready to be connected to the database. My code of connection is the follow :

<?php
    $host = "localhost";
    $db   = "clients";
    $user = "root";
    $pass = "";

    $con = mysqli_connect($host,$user,$pass,$db) or die('Could not connect to MySQL: ' .mysqli_connect_error());
?>

当我尝试使用WAMP执行页面时,它会向我返回消息:

When I try to execute the page with WAMP, it returns me the message :

警告:mysqli_connect():(HY000/1049):未知数据库客户端"

Warning: mysqli_connect(): (HY000/1049): Unknown database 'clients'

即使已经创建了数据库并执行了查询,它仍然会给我这个错误,就像数据库在PHP中使用了错误的名称或其他名称一样.

Even the database being already created and the queries executed, it still gives me this error, as if the database was with the wrong name in the PHP or something.

也许是由于没有来自用户root或使用localhost的密码而导致的错误?我该如何解决?

Maybe is the error from not having some password from the user root or using localhost ? How can I fix this ?

推荐答案

我前段时间在将MySQL数据库与node.js一起使用时遇到了此错误,我只是删除了该数据库并重新创建了它.虽然这很有趣,但是这就是我解决错误的方法.尝试使用另一个数据库名称再次创建数据库.

I came across this error sometime ago while using MySQL database with node.js, I just deleted the database and created it again. It's funny though, but that was how I solved the error. Try creating the database again with another database name.

这篇关于数据库已创建,但作为未知数据库返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆