Connecting to MySQL

Hello everyone. Help, I connect to MySQL and writes

Unable to connect to MySql server!

Although I have created a database. Here is the code and writes an error on line 6?

<?php
$host   = 'localhost';
$user   = 'root';
$pass   = 'syn21';
$dbname = 'synape';
if (!mysql_connect($host, $user, $pass))
    die('Не удалось подключиться к серверу MySql!');
elseif (!mysql_select_db($dbname))
    die('Не удалось выбрать БД!');
?>

Answer 1, authority 100%

$db = mysql_connect($host, $user, $pass) or die('Не удалось подключиться к MySql!');
mysql_select_db($dbname, $db) or die('Не удалось выбрать БД!');

P.S. And it would not be bad to display an error

mysql_connect($host, $user, $pass) or die('Облом!'.mysql_error());

Leave a reply

Please enter your comment!
Please enter your name here