Hello everybody. Help, connect to MySQL and write

Could not connect to MySql server!

Although I created a DB. 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('Не удалось выбрать БД!'); ?> 
  • 3
    Yes, on the sixth. - Oleg

1 answer 1

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

PS And not bad to display an error

 mysql_connect($host, $user, $pass) or die('Облом!'.mysql_error()); 
  • Sorry, but I did not understand - Anton
  • What exactly is not clear? And show the error that knocks when connecting, add to your query mysql_error () - Deonis
  • Warning: mysql_connect () [function.mysql-connect]: Access denied for user 'root' @ 'localhost' (using password: YES) in Z: \ home \ synape \ www \ connectdb.php on line 6 Could not connect to MySql server! Here is the mistake - Anton
  • Did you put a password on root? And if so, was it written correctly in the request? - Deonis