Error: Unable to connect to mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
fawzan
Forum Newbie
Posts: 1
Joined: Mon Nov 29, 2010 12:15 pm

Error: Unable to connect to mysql

Post by fawzan »

Hi
I'm new to php and mysql world. I downloaded an open source discussion board. It asks Database name , DB Username and password while configuring for the first time. i entered database name as 'fluxbb' and the username as 'root' the password is null. but i got the below error. how can fix it??

Error: Unable to connect to MySQL and select database. MySQL reported: Unknown database 'fluxbb'.

Thanks in advance.
asyouwish
Forum Newbie
Posts: 6
Joined: Tue Nov 30, 2010 6:06 am

Re: Error: Unable to connect to mysql

Post by asyouwish »

The code below works for me. My suggestion would be that you create a new user with a password for MySql.

$host = "localhost";
$db = "myDatabaseName";
$user = "myUserName";
$pwd = "myPwd";

$mysqli = @new mysqli($host, $user, $pwd, $db);

After this you would do something like the code below to send questions to the database and handle the response.

$qr = "select * from groups where active order by group_order";

if(!$result = $mysqli->query($qr)) {
//
// Something went wrong, may you'd like to print something to a log file.
//
}
else {
while($row = $result->fetch_assoc()) {
echo $row["id"] . "//" . $row["number"] . "//" . $row["group_order"] . "//" . $row["heading"];
}
}

I hope this will get you going. Now you just have to get into the wonderful world of SQL.
Post Reply