Connect MySQL localhost

PHP & MySQL Code:


mysql_connect("localhost", "admin", "1admin") or die (mysql_error());

echo "Connected to MySQL
";

?>


Display:

Connected to MySQL


The mysql_connect function takes three arguments. Server, username, and password. In our example above these arguments were:

  • Server - localhost
  • Username - admin
  • Password - 1admin


The "or die(mysql..." code displays an error message in your browser if --you've probably guessed it -- there is an error in processing the connection! Double-check your username, password, or server if you receive this error.

Tidak ada komentar: