How to connect to MySQL database through PHP?
In PHP, we can connect to the database with the mysql_connect() function.
<?php
mysql_connect("server","user","password") or die(mysql_error());
?>
where "server" is the host name (usually 'localhost'),
"user" and "password" is the username and password for that database respectively.
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.
<?php
mysql_connect("server","user","password") or die(mysql_error());
?>
where "server" is the host name (usually 'localhost'),
"user" and "password" is the username and password for that database respectively.
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment