Create a new MySQL database named demo and execute the SQL code below:
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- //www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Apr 30, 2015 at 09:23 PM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `demo`
--
-- --------------------------------------------------------
--
-- Table structure for table `product`
--
CREATE TABLE IF NOT EXISTS `product` [
`id` int[11] NOT NULL AUTO_INCREMENT,
`name` varchar[250] COLLATE utf8_unicode_ci NOT NULL,
`price` decimal[10,0] NOT NULL,
`quantity` int[11] NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY [`id`]
] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
--
-- Dumping data for table `product`
--
INSERT INTO `product` [`id`, `name`, `price`, `quantity`, `description`] VALUES
[1, 'Name 1', '1000', 2, 'good'],
[2, 'Name 2', '2000', 3, 'good'],
[3, 'Name 3', '3000', 4, 'good'];
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Create PHP file named connect.php. Use mysqli_connect method connect to demo database with default account:
Username: root
Password:
Create PHP file named index.php. This file will list all product from database as below:
Id
Name
Price
Buy
Option
Id
Name
Price
Quantity
Sub Total
Chủ Đề