How do I Connect a website in MySql?
Published: July 5, 2009
Question:
How do I Connect a website in MySql?
Answer:
If you want to connect your website to a MySQL database. There are a number of steps.
- You must make sure your hosting company offers that service and that you have that feature on your current hosting account.
- You must create the database with a user name and password. You can manipulate your database(s) using a program called phpMyAdmin. This is usually provided by your host company.
- Youmust use a scripting language to connect with. Usually of you are using MySQL then the language will be PHP.
- You then create the php page and upload it up to your sever.
- The following sample will allow you to connect your php page to the database. It does NOT do anything else other than connect. There are too many other variables on the type of table created and what you may want to do to show a general example.
Example:
<?php
//Usually this is localhost. But could be an address of the database server
$HostType = "locahost";
//Name of your database
$DatabaseName = "SomeName";
//Your database username
$DbaseUsername = "SomeUsername";
//Your database password
$DbasePassword = "SomePassword";
$db=mysql_connect($HostType,$DbaseUsername,$DbasePassword);
mysql_select_db($DatabaseName,$db) or die ("cant change");
//code to manipulate the data base
?>
About the Author
Rich Agnew is an author for The Computer Geek Custom Web Page Design. The Computer Geek is a web design company that prides itself in professional service at a fraction of the cost. The Computer Geek specializes in Custom Web Design, PHP & MySql and Ecommerce.