MySQL Connect
This shows you how to code a connection to the mySQL database.
Before your page can interact with your database it has to connect to it first. The first line of the connection script asks for the location of the database, the username, and password. The second line of the script asks for the database name. Both lines are set up to kill the script if it doesn't get the required information.The most convenient thing to do is to put all the connection information into a PHP file and use an include statement to insert the information in any page you need. This way if your password or something changes you only have to change one file. Also, if you do this then keep the included file outside of your public directory so visitors can't access it with their browser. If it is a PHP file then users of your page shouldn't be able to view it anyway but putting that file in a non-public directory is still something that should be done.
CONNECT
PHP Page
|
<html> <head> <title>HTML tutorial</title> </head> <body> <?php mysql_connect("host", "user", "password") or die(mysql_error()); mysql_select_db("databasename") or die(mysql_error()); $query = "INSERT INTO table VALUES ('$name','$address')"; mysql_query($query); mysql_close(); ?> </body> </html> |
||
Bookmark this page: |
Rate this page: |
Comments:
| please post comments | ||
|
admin November 21, 2006 |
||











