Introduction to PHP and MySQL – Creating Database-Driven Websites - Using WAMP
Introduction to PHP and MySQL – Creating Database-Driven Websites Connecting to MySQL database on your WAMP Web Server Start / Run.. Enter mysql –h localhost –u root –p There is no password set by default on WAMP Server. Do NOT set a password.
Introduction to PHP and MySQL – Creating Database-Driven Websites Connecting to MySQL database on your WAMP Web Server Start / Run.. Enter mysql –h localhost –u root –p Or Access the command line interface using WAMP’s pop-up menu
Introduction to PHP and MySQL – Creating Database-Driven Websites MySQL commands: Show databases; Use database-name; Explain table-name; or describe table-name;
Introduction to PHP and MySQL – Creating Database-Driven Websites MySQL commands: Create database garage; Show databases; Use garage; Create table cars(id int, make text, model text); Describe cars; Drop table cars;
Introduction to PHP and MySQL – Creating Database-Driven Websites MySQL commands: Create table cars (id int auto_increment, make varchar(20) not null, model varchar(20) not null unique, primary key (id) ); Explain cars; Insert into cars values (1, “Porsche”, “Carrera”); Select * from cars; Insert into cars (make, model) values (“Ferrari”, “Dino”), (“Lamborghini”, “Diablo”);
Introduction to PHP and MySQL – Creating Database-Driven Websites MySQL commands: Alter table cars add top_mph int; Select * from cars; Update cars set model = “911 Turbo” where id=1; Update cars set model = “F355” where make=“Ferrari”;
Introduction to PHP and MySQL – Creating Database-Driven Websites MySQL commands: Update cars set model = “Murcielargo” where make=“Lamborghini”; Update cars set top_mph=189 where id=1; Update cars set top_mph=183 where id=2; Update cars set top_mph=205 where id=3; Select * from cars;
Introduction to PHP and MySQL – Creating Database-Driven Websites MySQL commands: Delete from cars where id = 3; Alter table cars drop top_mph; Drop table cars; Drop database garage; Select * from cars;
Introduction to PHP and MySQL – Creating Database-Driven Websites Using PHPMyAdmin Create a new database BookShop Under Create New Table, enter Books Number of Fields = 6 First field: Field = Bkid, Type = INT, Index = Primary, A_I for Auto Increment.
Introduction to PHP and MySQL – Creating Database-Driven Websites Add records to your table: Field Type Lengths/Values Title VARCHAR 255 Author 60 Publisher Price DECIMAL 10, 2 Category 20
Introduction to PHP and MySQL – Creating Database-Driven Websites Other fields: Title Author Publisher Price Category Nightfall Asimov Bantam 5.99 Sci Fi Patriot Games Clancy Berkeley 4.95 Thriller 2010 Clarke Ballantine 3.95 Lie Down with Lions Follett Signet Mystery A Thief of Time Hillerman Harper The Fly on the Wall Hornet Flight 7.99 The Innocent Man Grisham Dell Mission of Honour
Using the MySQL Console Show all tables Use the Bookshop database Show all the tables Show the Books table structure Display all Books records Display all books within the category ‘Thriller’