Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Loading...
User Settings
close menu
Welcome to Scribd!
Upload
Read for free
FAQ and support
Language (EN)
Sign in
0 ratings
0% found this document useful (0 votes)
9 views
Unit - IV (Database Handling in PHP& Mysql)
Uploaded by
athifaparveez429
AI-enhanced
Reading
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Download
Save
Save Unit -IV (Database Handling in php& mysql) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Unit - IV (Database Handling in PHP& Mysql)
Uploaded by
athifaparveez429
0 ratings
0% found this document useful (0 votes)
9 views
6 pages
AI-enhanced title
Document Information
click to expand document information
Reading
Original Title
Unit -IV (Database Handling in php& mysql)
Copyright
© © All Rights Reserved
Available Formats
PDF or read online from Scribd
Share this document
Share or Embed Document
Sharing Options
Share on Facebook, opens a new window
Facebook
Share on Twitter, opens a new window
Twitter
Share on LinkedIn, opens a new window
LinkedIn
Share with Email, opens mail client
Email
Copy link
Copy link
Did you find this document useful?
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Is this content inappropriate?
Report
Reading
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Download now
Download as pdf
Save
Save Unit -IV (Database Handling in php& mysql) For Later
0 ratings
0% found this document useful (0 votes)
9 views
6 pages
Unit - IV (Database Handling in PHP& Mysql)
Uploaded by
athifaparveez429
AI-enhanced title
Reading
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Save
Save Unit -IV (Database Handling in php& mysql) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download as pdf
Jump to Page
You are on page 1
of 6
Search inside document
Fullscreen
CHAPTER 9Q DATABASE HANDLING USING PHP WITH MySQL — pate Handling Using PHP with MySQL: Introduction to MySQL: Database terms, Data S. eee: | According to MySQL’s Web site, www mysql.com, MySQL is the world’s most popular opensource database application and is widely used with PHP. MySQL software includes the database server (which keeps the actual data), various client apps (for interacting with the database server) and a number of uilities. In this chapter, you'll leam how to create a simple table by utilizing MySQL’s permitted data types and other attributes. Then you'll learn how to use two separate client apps to interface with the MySQL server, [92 NAMING DaTitbasE COMPONENTS NENTS. ig with databases, you must first determine your requirements. The application’s (or Web site's) objective dictates how the database should be designed. Keeping this in mind, the examples in this and the following chapters will make use of a database that maintains Some user registration information. When constructing databases and tables, use names (technically known as identifiers) that are clear, meaningful, and easy to type. > Identifiers should also comprise only letters, integers, andthe underscore (no spaces). ® Should not be the same as a pre-existing keyword (such as a SQL term or function name) n should be considered case-sensitive, > Cannot exceed 64 characters (roughly). It must be distinctive within its field. > This last rule states that a table cannot have two columns with the same name, nor can a database have two tables with the same name. Vv{tables in the same ¢ wo distinc the syntax for d you prevent difficult ame int However, you can use the same column nally fact, you should). These restrictions can be + will help it wil Following these guidelines is a sensible restriction tha z= [93 DATABASE TERMS To Name a Database’s Elements: i base: 1. Determine the Name of the Datal «rage Simply ensure that the databag This is the simplest and, perhaps, least significant PAT Web host will most like) a is unique to that MySQL server. If you use a hos! pathereve count or domain name “ly Of you with a database name that may or may not include Your SF : Because the information and processes might @PP! initial example will be called site name. 2. Determine the Names of the Tables: The table names only need to be unique within table in this example, which records user registration 3. Choose the Column Names for Each Table. Columns in the user's table will record a user ID, a e password, and the registration date. Table 4.1 displays these columns with sample data appropriate identification. Because MySQL offers a password function, I modified the name of, field to simply pass. This isn't exactly necessary, but it's a great concept. Table No. 4.1: Users Table : TAZA LS Column Name Example | gy user_id 834. - first_name ‘Bary 0110) eit baw 2a ct eaifae TOMaAROTAT A 1 ly to any’ generic site, the database j, re first name, a last name, an email do last_name Database Handling using PHP wi After you’ ve identified establish the data type for each column will contain when youLusing PHP with yp soosse Handi p evel a 153. Almost every database appr _——_—____ aaa ation falls into Retreat (aloo “into one of three categories: known as Strings) > Numeric > Time and date You can utilize severa} Variations ji rhe precise Selection of cotymn son’ inside MN type sv, but it also influences the gy, ann NOt only determines what information may be stored and wgthe MySQL kinds, how much space tormanee of the database. Table 4.2 includes the majority senoted that some of the one Y ‘ake up, and brief descriptions of each type. It should ‘Se res iT “strictions may vary between MySQL versions. Many of the types have an optional Lenj some of which are MySQL-specific. ets, [], denote an th feature, which limits their size. (The square | a ar tisks dar araineter that should be enclosed in parentheses:) You should limit Ber csracter string into a CHA 9 ach column for performance reasons. However, inserting, fa wb first wo haat at ie Column will result in truncation of the final three characters r 1 st ; a Or, wih a size (CHAR, VARCHAR ae the rest will be lost forever). This is true for any field » and so on). As a result, your length should always to th i sorrespond' to the greatest feasible value (as a number) or string (as text) that can be saved. —___ Table No. 42: MySQL. Data Types Type Size Description CHAR [Length] Length bytes A fixed-length field from 0 to 255 | characters long, | VARCHAR [Length] String length+1or2 [A variable-length field from 0 to | bytes 65,535 characters long. | TINY TEXT String length + 1 bytes | A string witha maximum length of 255 characters. TEXT String length + 2 bytes | A string with a maximum length of | 65,535 characters. MEDIUMTEXT String length + 3 bytes | A string with a maximum length of 16,777,215 characters. on LONGTEXT String length + 4 bytes | A string with a maximum length of 4,294,967,295 characters TINYINT [Length] I byte Range of -128 to 127 or 0 to 255 unsigned. SMALLINT [Length] 2 bytes Range of -32,768 to 32,767 or 0 to ___ | 65,535 unsigned. MEDIUMINT [Ler 3 bytes Range of -8,388,608 to 8,388,607 or 0 De to 16,777,215 unsigned. INT ‘4 byles Range of -2,147,483 to 2,147,483,647 tics) or 0 to 4,294,967,295.ee % Description 1s4 -_ PUP 4 | f -9,223,372,036,854 Type = | Range ot 936,854 s 9,223, ne rd ve Yi 46,744,07 3,709,551,61 unsigned ‘A. small number with float FLOAT [Length, | 4 bytes | decimal point Decimals] | ‘Atarge number with a floating decimg DOUBLE [Length, 8 bytes point. Decimals) ‘A Double stored as a string, allowing DECIMAL [Length, | Length + Lor 2byt®S | © 4 fixed decimal point _ Decimals] ___——T7 the format of YYYY-MM-DD E by ahh bo cm f | DATE el __3byKS the format of YYYY-MM.pp DATETIME | 8 bytes HH:MM:SS___ a i Tq the format of YYYYMMpp) TIMESTAMP 4 bytes ISS; acceptable range start i, 1970 and ends in the year 2038. ae ee Te Tn the format of HH:MM:SS. EN ieeatye Short for enumeration, which mean that each column can have one of, several possible values. | SET To 5d or 8 bytes || Bile NUR extent. tat cach cole we can have more than one of sever) possible values. | 9.4.1 To Choose the Column Types: 1. Determine if a column should be of the text, number, or date/time format (Table 4.3); Normally, this is a simple and straightforward process, but you want to be as specifics possible. The date 2006-08-02 (MySQL format), for example, could be kept as a string-August 2, 2006. However, if you use the correct date format, you'll have a more useful database’ (and, as youll see, there are functions that can conyert 2006-08-02 to August 2, 2006). Table No. 4.3: Users Table Column Name Type user_id Number first_name Text last_name Text email Text pass: Text Fesistrationldats Date/TimeDatabase Handling using PHP wir, aS 2. Sel ee umn (Table 4.4): ct the best subtype for each colt The user_id is set ag million values (as an 1a MEDIUMINT in this example, allowing for up to approximately 17 DATETIME. ttmay a. 8°40 non-negative munber) The Tegistration_date is going to be a ss only the dat ae date as well as the exact time a user registered. Consider if you'll want : © date, the time, or mayb ay side of storing too much data Pte to na eke sal Senerally be VARCHAR because their lengths will vary from record to recor he Ption is the password column, which will be « fixed-length CHAR (you'll \ discover why in the next chapter when entering entries). More information on these ‘wo kinds can be found in the "CHAR vs. VARCHAR" sidebar. | Table No. 4.4: Users Table ; ___ Column Name Type ' user_id MEDIUMINT first_name VARCHAR last_name VARCHAR email VARCHAR pass CHAR 7 Tegistration_date DATE TIME "3, Define the maximum text column length (Table 4.5): » Any ficld’s size should be limited to the smallest possible value based on the largest possible Fioput. For instance, if column has a state abbreviation, itis defined as a CHAR(2). Other times, you | may have to gues: I can’t think of any first names longer than roughly 10 characters, but I’ll allow "for up to 20 just to be safe. Table 4.5: Users Table Column Name Type user_id MEDIUMINT | first_name VARCHAR (20) | ! last_name VARCHAR (40) email VARCHAR (60) pass CHAR (40) registration_date DATE TIME oo i a |ClCUPHP & 4 = 18g 186 ‘olumn Properties: “ee onal Col ves wo employ for Your ¢ plumns, YOu shoyy 9.4.2 Choosing Ad . si Aside from determining the data types and consider a few other properties. Nt das NOT NULL. In dataty To begin with, any column, regardless of tyPe, CAR hed aa value — and programming, the NULL value means that the field has peeiereiet table in a correctly const ASE shouly Ideally, every column of every row in every ery vada the NOT NULL description tothe col 1 case. have a value, however this isn’t always the for example, can be ex; a ‘Press type to force a field to have a value. A required mon s as cost DECIMAL (5,2) NOT NULL. etary amount, yy column, regardless of tyPe> when creating a table, jy ds will have the same value for a column, Choosing » serting new rows (unless that row’s valye You can also give a default value for an; circumstances when the majority of the reco v default saves you from having to specify a value when in: for that column differs from the norm). ENUM(‘M’, ‘F’) gender default ‘F” If no value is Supplied for the gender field when adding a record, the default will be used. When the number types are marked as UNSIGNED, the recorded data is limited to positive values and zero. This practically increases the range of positive integers that can be stored (sin no negative values are preserved, as shown in Table 4.2). You can additionally mark the number types as ZEROFILL, which indicates that any exty space is immediately padded with zeros (ZEROFILLs are also automatically UNSIGNED). 9.5 MODEL QUESTIONS i i ei : ‘Answer the following questions. 6 or 8 marks 1. What are some common terms used in databases and what do they mean? 2. Describe MySQL Datatypes. ‘i kt
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
Rating: 4 out of 5 stars
4/5 (6024)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
Rating: 4 out of 5 stars
4/5 (626)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
Rating: 4 out of 5 stars
4/5 (1133)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
Rating: 4.5 out of 5 stars
4.5/5 (911)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
Rating: 4.5 out of 5 stars
4.5/5 (1741)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
Rating: 4 out of 5 stars
4/5 (1245)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
Rating: 4 out of 5 stars
4/5 (628)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
Rating: 4 out of 5 stars
4/5 (937)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
Rating: 4.5 out of 5 stars
4.5/5 (2121)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
Rating: 4.5 out of 5 stars
4.5/5 (548)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
Rating: 4.5 out of 5 stars
4.5/5 (359)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
Rating: 4.5 out of 5 stars
4.5/5 (481)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
Rating: 4 out of 5 stars
4/5 (1062)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
Rating: 4.5 out of 5 stars
4.5/5 (275)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
Rating: 4.5 out of 5 stars
4.5/5 (821)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
Rating: 4.5 out of 5 stars
4.5/5 (444)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
Rating: 4 out of 5 stars
4/5 (99)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
Rating: 3.5 out of 5 stars
3.5/5 (2281)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
Rating: 4 out of 5 stars
4/5 (1954)
Yes Please
From Everand
Yes Please
Amy Poehler
Rating: 4 out of 5 stars
4/5 (1961)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
Rating: 4.5 out of 5 stars
4.5/5 (273)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
Rating: 4 out of 5 stars
4/5 (4264)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
Rating: 4.5 out of 5 stars
4.5/5 (1934)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
Rating: 3.5 out of 5 stars
3.5/5 (233)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
Rating: 4.5 out of 5 stars
4.5/5 (235)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
Rating: 4 out of 5 stars
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
Rating: 3.5 out of 5 stars
3.5/5 (140)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
Rating: 3.5 out of 5 stars
3.5/5 (805)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
Rating: 3.5 out of 5 stars
3.5/5 (883)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
Rating: 4 out of 5 stars
4/5 (45)
John Adams
From Everand
John Adams
David McCullough
Rating: 4.5 out of 5 stars
4.5/5 (2520)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
Rating: 3.5 out of 5 stars
3.5/5 (109)
Little Women
From Everand
Little Women
Louisa May Alcott
Rating: 4 out of 5 stars
4/5 (105)