PHP-MYSQL.ppt - CMSC 127 Create Table joke CREATE TABLE joke id INT NOT NULL AUTO_INCREMENT PRIMARY KEY joketext TEXT jokedate DATE NOT NULL authorid

PHP-MYSQL.ppt - CMSC 127 Create Table joke CREATE TABLE...

  • No School
  • AA 1
  • 46

This preview shows page 1 - 17 out of 46 pages.

CMSC 127
Image of page 1

Subscribe to view the full document.

Image of page 2
CREATE TABLE joke ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, joketext TEXT, jokedate DATE NOT NULL, authorid INT ) DEFAULT CHARACTER SET utf8; Create Table joke
Image of page 3

Subscribe to view the full document.

CREATE TABLE author ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255) ) DEFAULT CHARACTER SET utf8; Create Table author
Image of page 4
CREATE TABLE category ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) ) DEFAULT CHARACTER SET utf8; Create Table category
Image of page 5

Subscribe to view the full document.

CREATE TABLE jokecategory ( jokeid INT NOT NULL, categoryid INT NOT NULL, PRIMARY KEY (jokeid, categoryid) ) DEFAULT CHARACTER SET utf8; Create Table jokecategory
Image of page 6
INSERT INTO author (id, name, email) VALUES (1, 'Kevin Yank', '[email protected]'), (2, 'Joan Smith', '[email protected]'); Insert date into author
Image of page 7

Subscribe to view the full document.

INSERT INTO joke (id, joketext, jokedate, authorid) VALUES (1, 'Why did the chicken cross the road? To get to the other side!', '2009-04-01', 1), (2, 'Knock-knock! Who\'s there? Boo! "Boo" who? Don\'t cry; it\'s only a joke!', '2009-04-01', 1), (3, 'A man walks into a bar. "Ouch."', '2009-04-01', 2), (4, 'How many lawyers does it take to screw in a lightbulb? I can\'t say for fear of being sued.', '2009- 04-01', 2); Insert date into joke
Image of page 8
INSERT INTO category (id, name) VALUES (1, 'Knock-knock'), (2, 'Cross the road'), (3, 'Lawyers'), (4, 'Walk the bar'); Insert date into category
Image of page 9

Subscribe to view the full document.

INSERT INTO jokecategory (jokeid, categoryid) VALUES (1, 2), (2, 1), (3, 4), (4, 3); Insert date into jokecategory
Image of page 10
<html> <head> <title>Joke CMS</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <h1>Joke Management System</h1> <ul> <li><a href="jokes/">Manage Jokes</a></li> <li><a href="authors/">Manage Authors</a></li> <li><a href="categories/">Manage Joke Categories</a></li> </ul> </body> </html> Index.html
Image of page 11

Subscribe to view the full document.

Image of page 12
<?php $link = mysqli_connect('localhost', 'root', 'password'); if (!$link) { echo 'Unable to connect to the database server.'; exit(); } if (!mysqli_set_charset($link, 'utf8')) { echo 'Unable to set database connection encoding.'; exit(); } if (!mysqli_select_db($link, ‘joke')) { echo 'Unable to locate the joke database.'; exit(); } ?> db.inc.php
Image of page 13

Subscribe to view the full document.

Image of page 14
The built-in function mysqli_connect establishes a connection to a MySQL server: mysqli_connect( hostname , username , password ) $link = mysqli_connect('localhost', 'root', ' password '); $link = mysqli_connect('localhost', 'root', ' password '); if (!$link) { echo “Unable to connect to the database server.”; exit(); }
Image of page 15

Subscribe to view the full document.

MySql uses ISO-8859-1 encoding instead of UTF-8 Set character encoding
Image of page 16
Image of page 17
  • Fall '19
  • Character encoding, ASCII, Unicode

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes