Page 1 of 1

Error: Unable to connect to mysql

Posted: Mon Nov 29, 2010 12:27 pm
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.

Re: Error: Unable to connect to mysql

Posted: Tue Nov 30, 2010 3:23 pm
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.