sábado, 19 de maio de 2007

Connect to a database using Mysql

PHP main target is to make possible build dynamic web sites.
This possibility is available by using some database system to store information and manipulate them, when system and user needs it.
On PHP a large number of database systems come by default embbed as libraries.
On this article we will learn how to use one of the most used on data handling - MySQL.
MySQL can be installed easly, by downloading EasyPHP.
This application installs Mysql on a web based version, it means that you can manage all database processes on your browser.
It allows to create databases, and tables, edit fields , backup tables system database and a large option of new features.
To access the interface that allows you to create database click with the right button of mouse on tray icon "Administration".
Right next click

MySQL MANAGER

it will open the window where you must the name of your database and next it will ask for your table name.

Check how many fields you need on your table and build it.

Now the database and table are created let´s configure the conection to the mysql server using PHP.
Remember that server is configured with an default username and password.
You can make secure by changing it at your choice.

Follows the PHP code generated to build the table


Here´s a simple php-mysql snnipet to connect mysql host