PHP MySQL Tutorial Connect to MySQL

2007-11-02 21:45 来源: web 作者:phpma 网友评论 0 条 浏览次数 0

PHP MySQL Tutorial Connect to MySQLphpma.com

Interacting with MySQL makes PHP a far more powerful tool. In this tutorial we will go through some of the most common ways PHP interacts with MySQL. To follow along with what we are doing, you will need to create a database table by executing this command:

 

CREATE TABLE friends (name VARCHAR(30), fav_color VARCHAR(30), fav_food VARCHAR(30), pet VARCHAR(30));
INSERT INTO friends VALUES ( "Rose", "Pink", "Tacos", "Cat" ), ( "Bradley", "Blue", "Potatoes", "Frog" ), ( "Marie", "Black", "Popcorn", "Dog" ), ( "Ann", "Orange", "Soup", "Cat" ) phpma.com

This will create a table for us to work with, that has friends' names, favorite colors, favorite foods, and pets.

The first thing we need to do in our PHP file is connect to the database. We do that using this code:

 

<?php phpma.com
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>

Of course you will replace server, username, password, and Database_Name with the information relevant to your site. If you are unsure what these values are, contact your hosting provider.

上一篇:"Abs () PHP Func..    下一篇:PHP MySQL Tutori..

相关主题:

网友评论