Wednesday, September 11, 2013

Lets Make our Php talk to MySql

OK this is going to be fun..

Assignment4 PHP II
create a table our your demoserver a connection
with a host 
use id instead of root and whatever database program will take my file and run it against your database
will create table for that database
how you get a table installed remotely 
take the statement split it up and run it line by line

CREATE A STUDENTS TABLE STUDENT ID NAME ADDRESS CITY STATE MAJOR GPA 

FORMAT OF MY TABLE NAME IS GOING TO BE  FIRST INITIAL LAST NAME STUDENTTABLE
DRIDDLESPURSTUDENTTABLE
WHEN TESTING CREATING WHATEVER JUST CREATE IT WITH THIS NAME TO BEGIN WITH THAT WAY WHEN YOU DUMP IT , ITS GOING TO PULL THAT NAME A  NIQUE NAME SO THAT WHEN WE INSTALL IT ON YOUR SERVER IT HAS A UNIQUE NAME
WRITE A PROGRAM THAT IS GOING TO DISPLAY THE INFO THAT IS IN THAT TABLE 
AT THAT POINT
ABILITY TO DO SOME SORT OF UPDATE TO THAT PARTICULAR TABLE 
MAYBE FOR EXAMPLE YOU DO DO A DROPDOWN BOX WHERE YOU GIVE THEM THE STUDENT ID THEY SELECT IT AND IT GIVES THEM THE ABILITY TO CHANGE SOMETHING FOR THAT STUDENT. 
In plain English:


Ok so we create a page kinda like assignment 2 the exception being the information is populated by SQL instead of XML. On that page would be some kind of radio button that when selected brings up an edit page. When then information is edited and the select button on that page is clicked it brings up the first page showing the edited version of the information.


Php is well known for its seamless database integration,Once you establish the connection, you can send your SQl commands to the database and receive the results as data you can use in your PHP program. This is not hard to accomplish if you learn the basic tools to accomplish the task. 

  • Get a connection to a MYSql database from within PHP
  • Use a particular database
  • Parse the query results
  • Check for data errors
  • build HTML output from data results
<?php
//make the database connection
$

Friday, August 30, 2013

Ok its about to get real.. Welcome to PHP2…
Something Important.. if you have a MacBook Pro..
I had to download MAMP  .
Be sure to put it in your Applications folder after you extract it.
In your finder search bar type in "terminal"


Open your terminal window…Type this in

mysql -uroot -p

It will ask for your password and it should be root unless you have changed it..

The first assignment: Create a mySQL script in the command prompt( terminal window..  that will create a database, and table for student information. Include at least five fields, and at least five rows of data. Also include an ability to display all the records at the end of the script.Turn In:

1. The script itself

2. A screen shot showing the output of the script when run

Assignment 3.sql

CREATE DATABASE cist_Students;
USE cist_Students;


CREATE TABLE my_Students (
id INT PRIMARY KEY,
firstName VARCHAR (15),
lastName VARCHAR(15),
email VARCHAR(20),
phone VARCHAR(15),
major VARCHAR (15),
gpa VARCHAR (3)
);
INSERT INTO my_Students VALUES (
0, 'steve', 'smith', 'this@that.com', '455-4543',' nurse' , '3'),
(1, 'deanna', 'dobbibs', 'she@that.com', '545-4543',' programming' , '4.0'),
(2, 'lucy', 'jones', 'lucy@that.com', '645-4543',' art' , '3.0'),
(3, 'aubie', 'eagle', 'eagle@that.com', '895-4543',' sports' , '3.5'),
(4, 'robert', 'hairman', 'weagle@that.com', '998-4543',' history' , '3.0');

SELECT * FROM my_Students;
This is what it will look like in the terminal window on the mac:

When you open up phpmyadmin and go to your database and choose the table you created, you will see the data inserted. TADA the magic of SQL :-)

Restore database files

Restoring database files at home or in the classroom
Using CD to get to the bin location as shown in the backup directions.
Then execute:

mysql -u root -p -D mydatabase < mydatabase.sql
The program will prompt you for a password..just hit enter
You will not recieve any message back. However, you should be able to go into phpmyadmin and see the results.