Connecting to MySQL database

This tutorial will show you how to connect to mysql database. It's easy to write a script to connect to world's most popular opensource database.

Define your database information,
* host="localhost" you don't have to change it. When it's on your computer or server it still be localhost

Username = admin
Password = 1234
Database = test
 

Test 









Creating file config.php













Inserting data into mysql 

In this tutorial create 2 files
1. insert.php
2. insert_ac.php

Step
1. Create table "test_mysql" in database "test".
2. Create file insert.php.
3. Create file insert_ac.php.

Create table "test_mysql"

CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=0 ;











Create file insert.php
 








Code




















Create file insert_ac.php























Code 
Deleting data From mysql
Delete unwanted data from your mysql database.

In this tutorial create 2 files
1. delete.php
2. delete_ac.php

Step
1. Create table "test_mysql" in database "test".
2. Create file delete.php.
3. Create file delete_ac.php.

Set up database

CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=7 ;
--
-- Dumping data for table `test_mysql`
--
INSERT INTO `test_mysql` VALUES (1, 'Billly', 'Blueton', 'bb5@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (2, 'Jame', 'Campbell', 'jame@somewhere.com');
INSERT INTO `test_mysql` VALUES (3, 'Mark', 'Jackson', 'mark@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (4, 'Linda', 'Travor', 'lin65@phpeasystep.com');
INSERT INTO `test_mysql` VALUES (5, 'Joey', 'Ford', 'fordloi@somewhere.com');
INSERT INTO `test_mysql` VALUES (6, 'Sidney', 'Gibson', 'gibson@phpeasystep.com');
  
Create file - delete.php
Code




Create file delete_ac.php

Code


Creating a simple PHP guestbook

Overview In this tutorial create 3 files
1. guestbook.php
2. addguestbook.php
3. viewguestbook.php

Step
1. Create table name "guestbook" in database "test".
2. Create file guestbook.php.
3. Create file addguestbook. php.
4. Create file viewguestbook.php


Set up database








CREATE TABLE `guestbook` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`comment` longtext NOT NULL,
`datetime` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Create file guestbook.php












Code





















create file addguestbook.php






















Code



















Create file viewguestbook.php





















Code



AppServ

What is PHP?

PHP, which stands for "Hypertext Preprocessor", is a server-side, HTML embedded scripting language used to create dynamic Web pages. Much of its syntax is borrowed from C, Java and Perl with some unique features thrown in. The goal of the language is to allow Web developers to write dynamically generated pages quickly. In an HTML page, PHP code is enclosed within special PHP tags. When a visitor opens the page, the server processes the PHP code and then sends the output (not the PHP code itself) to the visitor's browser. It means that, unlike JavaScript, you don't have to worry that someone can steal your PHP script. PHP offers excellent connectivity to many databases including MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, and Generic ODBC. The popular PHP-MySQL combination (both are open-source products) is available on almost every UNIX host. Being web-oriented, PHP also contains all the functions to do things on the Internet - connecting to remote servers, checking email via POP3 or IMAP, url encoding, setting cookies, redirecting, etc.

What do PHP code look like?
PHP is a rather simple language. Much of its syntax is borrowed from C except for dealing with the types of variables. You don't need to think of the types of variables at all - you just work with their values, not their types. And you don't have to declare variables before you use them.
Basic Syntax
  • File name:
    You should save your file with the extension .php (earlier versions used the extensions .php3 and .phtml).
  • Comments:
    // This comment extends to the end of the line.
    /* This is
    a multi-line
    comment
    */
  • Escaping from HTML:
    A PHP code block starts with "
    ". A PHP code block can be placed anywhere in the HTML document.
  • Instruction separation:
    Each separate instruction must end with a semicolon. The PHP closing tag (?>) also implies the end of the instruction.

 What Does MySQL Mean?

MySQL is a type of database, and it is popular with several Content Management Systems and widely available. There are many types of databases, so you should make sure that the type of database offered by your host is compatible with the software you plan to use.

Installing Appserv on Windows
Installing Apache Web Server, php and MySQL individually on Windows is not easy task. Because it might takes long time time to make so many configurations to work well such as editing in .ini setting, httpd.conf and many services and extensions used by Apache, php and MySql.
Appserv includes Apache, php, MySQL and phpMyAdmin in one package and you can install in a minute without make any configuration.
Let’s get started.
  • Check the version history from Appserv.
  • Download the latest stable released Appserv windows installer version from SourceForget.net.
Installing Appserv
Run the Appserv setup (.exe) file which you downloaded.
Before you install Appserv package make sure that you stop IIS if you has installed IIS in your machine because only one web server can run in single machine.
  • You’ll see Welcome Message, click ‘Next’
  • You’ll see License Agreement, click ‘Next’
  • Choose the installation directory, c:\appserv as default. Click “Next”.
  • Select the applications you wish to install, all of four services checked as default. Click ‘Next’.
  • Enter the Apache web server information. Normally, you can put whatever you want. In Web Server Name, you can put “www.example.com” or something like this. Administrator’s Email Address, put your email address or “k_man@example.com”.
  • Enter password for Mysql root user, enter a password which is easier to remember when you login to mysql database as root.
  • You’ll see installation progress.
  • Start Apache web server and Mysql service. Click “Finished”.
Source from: Google

My Picture


Search