Skip to main content

Posts

SQL Joins

1. Login in to the mysql client using the login name and password provided by your instructor (if not already logged in). 2. View the existing databases that the MySQL Server is maintaining. SHOW DATABASES; 3. Utilize the photo_album database. USE photo_album; ---- If Need be, recreate the database and load the SQL data in that will be used for this lab CREATE DATABASE photo_album; SOURCE /tmp/photo_album.sql; 4. Query the database to display the active primary customer (email, first and last name) and all the associated active login names associated with that customer. SELECT customers.email_customer, customers.fname, customers.lname, logins.login_name  FROM customers, logins WHERE customers.email_customer = logins.email_customer  AND customers.active_customer = 'True'  AND logins.active_login = 'True';

SQL DML Commands

1. Login in to the mysql client using the login name and password provided by your instructor (if not already logged in). 2. View the existing databases that the MySQL Server is maintaining. SHOW DATABASES; 3. Utilize the photo_album database. USE photo_album; ---- If Need be, recreate the database and load the SQL data in that will be used for this lab CREATE DATABASE photo_album; SOURCE /tmp/photo_album.sql; 4. Search the customers records for the customer with the following e-mail address: hollywood@truedog.com SELECT * FROM customers WHERE email_customer = 'hollywood@truedog.com'\G 5. Search the logins records for logins associated with the customer identified in step 4. SELECT * FROM logins WHERE email_customer = 'hollywood@truedog.com'; 6. In the customers table, update the customers e-mail address, identified in step 4, to howleewood@truedog.com. UPDATE customers SET email_customer = 'howleewood@truedog.com' WHERE email_custo

SQL Expressions

1. Login in to the mysql client using the login name and password provided by your instructor (if not already logged in). 2. View the existing databases that the MySQL Server is maintaining. SHOW DATABASES; 3. Utilize the photo_album database. USE photo_album; ---- If Need be, recreate the database and load the SQL data in that will be used for this lab CREATE DATABASE photo_album; SOURCE /tmp/photo_album.sql; 4. Calculate how many days ago each person logged into the photo_album system. Note: Difference in dates are returned in microseconds when directly subtracted from each other. SELECT login_name, ROUND((NOW() - last_login)/24/60/60/60) FROM logins; 5. List the actual day name (Monday, Tuesday, etc.) for the last logins to determine if there is a trend in the day of the week for the last time a person logged into the photo_album system. SELECT login_name, DAYNAME(last_login) FROM logins; 6. Modify the statement above by having the output show 'Weeke

SQL SELECT Commands

1. Login in to the mysql client using the login name and password provided by your instructor (if not already logged in). 2. In the photo_album databases, load the /tmp/photo_album.sql.data file into the database. USE photo_album; SOURCE /tmp/photo_album.sql; 3. Perform an aggregate select against each table to count the number of records located in each table. SELECT COUNT(*) FROM customers; SELECT COUNT(*) FROM comments; SELECT COUNT(*) FROM images; SELECT COUNT(*) FROM logins; 4. Using the customers table, list the customers who are active from closest to farthest termination date (term_date). SELECT * FROM customers WHERE active_customer='True' ORDER BY term_date ASC; 5. Using the logins table, list those with active logins and have logged in during the month of April 2007. SELECT * FROM logins WHERE active_login='True' && last_login LIKE '2007-04%'; 6. Using the images table, list the active images names from the most

Managing Database Tables

1. Login in to the mysql client using the login name and password provided by your instructor. 2. View the existing databases that the MySQL Server is maintaining. SHOW DATABASES; 3. Utilize the photo_album database. USE photo_album; 4. Create the first table called customers that will store the information related to the customers who have purchased access to the online photo album CREATE TABLE customers ( email_customer VARCHAR(50) NOT NULL DEFAULT '', f_name VARCHAR(20) NOT NULL DEFAULT '', l_name VARCHAR(30) NOT NULL DEFAULT '', addr1 VARCHAR(30) NOT NULL DEFAULT '', addr2 VARCHAR(30) NULL, addr_city VARCHAR(25) NOT NULL DEFAULT '', addr_state CHAR(3) NOT NULL DEFAULT '', addr_zip CHAR(10) NOT NULL DEFAULT '', primary_phone CHAR(12) NOT NULL DEFAULT '', secondary_phone CHAR(12) NULL, term_date DATE NOT NULL DEFAULT 0, active_customer ENUM('True', 'False') NOT NULL DEFAULT 

Managing Databases

1. Login in to the mysql client using the login name and password provided by your instructor. 2. View the existing databases that the MySQL Server is maintaining. mysql> SHOW DATABASES; 3. There should be only three databases that the MySQL Server is maintaining: INFORMATION_SCHEMA, mysql and test. Remove any additional databases that exist. If need be, mysql> DROP DATABASE db_name; 4. Create a new database called photo_album with a default character set of utf8. mysql> CREATE DATABASE photo_album CHARACTER SET utf8; 5. Using the mysql client, verify that the database was created. mysql> SHOW DATABASES; 6. View the contents of the /usr/local/mysql/data directory. Is there a new sub-directory associated with the database just created? >ls /usr/local/mysql/data/ 7. View the db.opt file located in the associated sub-directory to verify the correct default character set is being used. What collation type has been assigned as default? Does that mak

Counting Strings

Due to the fact that PHP's regular expressions are so versatile, many functions that have been designed by PHP developers have been overlooked in the past because the tasks were able to be completed with regular expressions. However, there are two functions that should not be overlooked due to their simplicity in performing a more complex task. • count_chars -                        This built-in function provides information about the number of times that an standard ASCII character appears in the string. <?php $text = "I went to Mississippi for the summer."; $letters = count_chars($text, 1); // 1 counts only the characters that show up more than zero times // 0 is the default and produces the entire listing of standard // ASCII characters, even those not showing up in the string // 2 returns only those ASCII characters that do not show up // 3 & 4 return byte info (all located and all unused, respectively) foreach($letters as $key=>$value)