Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
15 views
Unit - IV (Database Handling in PHP& Mysql)
Reading
Uploaded by
athifaparveez429
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Unit -IV (Database Handling in php& mysql) For Later
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
0 ratings
0% found this document useful (0 votes)
15 views
Unit - IV (Database Handling in PHP& Mysql)
Reading
Uploaded by
athifaparveez429
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Unit -IV (Database Handling in php& mysql) For Later
Carousel Previous
Carousel Next
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
You are on page 1
/ 6
Search
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
Ch4
PDF
No ratings yet
Ch4
19 pages
MySQL_ Data types
PDF
No ratings yet
MySQL_ Data types
8 pages
SQL Database
PDF
No ratings yet
SQL Database
13 pages
Unit I: Introduction To Mysql
PDF
100% (1)
Unit I: Introduction To Mysql
39 pages
Chapter01 Lesson04
PDF
No ratings yet
Chapter01 Lesson04
43 pages
Creating and Manipulating Tables in Mysql 1. Creating A Table in Mysql
PDF
100% (1)
Creating and Manipulating Tables in Mysql 1. Creating A Table in Mysql
7 pages
Selecting Mysql Database From Command Prompt:: Numeric Data Types
PDF
100% (1)
Selecting Mysql Database From Command Prompt:: Numeric Data Types
7 pages
PHP Unit V
PDF
No ratings yet
PHP Unit V
15 pages
Phpmyadmin DB Notes
PDF
No ratings yet
Phpmyadmin DB Notes
25 pages
Mysql Is An: Open-Source Relational Database Management System
PDF
No ratings yet
Mysql Is An: Open-Source Relational Database Management System
22 pages
UNIT-5 WORKING WITH DATABASE IN PHP
PDF
No ratings yet
UNIT-5 WORKING WITH DATABASE IN PHP
14 pages
Laboratory Manual On MYSQL For Year IV Database Students (Power and Control Engineering Stream Students)
PDF
No ratings yet
Laboratory Manual On MYSQL For Year IV Database Students (Power and Control Engineering Stream Students)
20 pages
5.introduction To MySQL
PDF
No ratings yet
5.introduction To MySQL
54 pages
mysql-data-types
PDF
No ratings yet
mysql-data-types
2 pages
DBMS Lab 3-4
PDF
No ratings yet
DBMS Lab 3-4
8 pages
MySQL Tutorial
PDF
No ratings yet
MySQL Tutorial
8 pages
Chap4 Introduction To SQL and MySQL
PDF
No ratings yet
Chap4 Introduction To SQL and MySQL
67 pages
DWPD GTU Study Material E-Notes Unit-5 03082019063134AM PDF
PDF
No ratings yet
DWPD GTU Study Material E-Notes Unit-5 03082019063134AM PDF
16 pages
Data Types
PDF
No ratings yet
Data Types
43 pages
DWPD GTU Study Material E-Notes Unit-5 22092020071825AM
PDF
No ratings yet
DWPD GTU Study Material E-Notes Unit-5 22092020071825AM
16 pages
Cs
PDF
No ratings yet
Cs
20 pages
PHP MySQL Module IV
PDF
No ratings yet
PHP MySQL Module IV
15 pages
Lec4 - Mysql - PHP
PDF
No ratings yet
Lec4 - Mysql - PHP
41 pages
PHP MySQL Create Database and Tables
PDF
No ratings yet
PHP MySQL Create Database and Tables
3 pages
MySQL
PDF
No ratings yet
MySQL
8 pages
PHP MySQL Create Table
PDF
No ratings yet
PHP MySQL Create Table
2 pages
Relational Databases and Mysql: This Work Is Licensed Under A
PDF
No ratings yet
Relational Databases and Mysql: This Work Is Licensed Under A
47 pages
Slide MySql
PDF
No ratings yet
Slide MySql
22 pages
Lecture3 PHP MySQL
PDF
No ratings yet
Lecture3 PHP MySQL
119 pages
Iwd Unit 5 Working With Database
PDF
No ratings yet
Iwd Unit 5 Working With Database
20 pages
Unit3 PHP
PDF
No ratings yet
Unit3 PHP
20 pages
WWW PHP Tutorials Info
PDF
No ratings yet
WWW PHP Tutorials Info
10 pages
SQL Labsheets
PDF
100% (1)
SQL Labsheets
98 pages
Data Types MySQL
PDF
No ratings yet
Data Types MySQL
2 pages
PHP 13
PDF
No ratings yet
PHP 13
57 pages
My SQL - Basic Concepts - 71766
PDF
No ratings yet
My SQL - Basic Concepts - 71766
13 pages
L9 SQL
PDF
No ratings yet
L9 SQL
128 pages
Basic To Advance Tutorial of SQL
PDF
No ratings yet
Basic To Advance Tutorial of SQL
37 pages
LAB 02 Data Types. Create and Alter Table Structure: V Main Contents
PDF
No ratings yet
LAB 02 Data Types. Create and Alter Table Structure: V Main Contents
12 pages
SQL Statement
PDF
No ratings yet
SQL Statement
9 pages
PHP 09 MySQL
PDF
No ratings yet
PHP 09 MySQL
58 pages
My SQL Instagram
PDF
No ratings yet
My SQL Instagram
9 pages
Basic Steps in MySQL
PDF
No ratings yet
Basic Steps in MySQL
62 pages
Lecture 15 - MySQL - PHP 1
PDF
No ratings yet
Lecture 15 - MySQL - PHP 1
81 pages
SQL Cheat Sheet
PDF
0% (1)
SQL Cheat Sheet
16 pages
Basics of PHP & MySQL
PDF
100% (9)
Basics of PHP & MySQL
7 pages
06 Working With Databases
PDF
No ratings yet
06 Working With Databases
5 pages
UNIT 5-Part 1
PDF
No ratings yet
UNIT 5-Part 1
9 pages
Introduction To Databases and SQL
PDF
No ratings yet
Introduction To Databases and SQL
38 pages
L23 - Mysql 1
PDF
No ratings yet
L23 - Mysql 1
49 pages
Short Notes 1 - MySQL Commands 1 1650270538687
PDF
No ratings yet
Short Notes 1 - MySQL Commands 1 1650270538687
26 pages
Basic PHP Database MYSQL For Beginners
PDF
100% (4)
Basic PHP Database MYSQL For Beginners
21 pages
Introduction To Mysql Server: Mysql Cluster - Provides Fault Tolerance
PDF
No ratings yet
Introduction To Mysql Server: Mysql Cluster - Provides Fault Tolerance
12 pages
Table Creation and DML Commands
PDF
No ratings yet
Table Creation and DML Commands
26 pages
Computer 3
PDF
No ratings yet
Computer 3
18 pages
C9 MySQL1
PDF
100% (2)
C9 MySQL1
56 pages
Data Types
PDF
No ratings yet
Data Types
3 pages
Mysql
PDF
No ratings yet
Mysql
24 pages
unit 2
PDF
No ratings yet
unit 2
96 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
Ch4
PDF
Ch4
MySQL_ Data types
PDF
MySQL_ Data types
SQL Database
PDF
SQL Database
Unit I: Introduction To Mysql
PDF
Unit I: Introduction To Mysql
Chapter01 Lesson04
PDF
Chapter01 Lesson04
Creating and Manipulating Tables in Mysql 1. Creating A Table in Mysql
PDF
Creating and Manipulating Tables in Mysql 1. Creating A Table in Mysql
Selecting Mysql Database From Command Prompt:: Numeric Data Types
PDF
Selecting Mysql Database From Command Prompt:: Numeric Data Types
PHP Unit V
PDF
PHP Unit V
Phpmyadmin DB Notes
PDF
Phpmyadmin DB Notes
Mysql Is An: Open-Source Relational Database Management System
PDF
Mysql Is An: Open-Source Relational Database Management System
UNIT-5 WORKING WITH DATABASE IN PHP
PDF
UNIT-5 WORKING WITH DATABASE IN PHP
Laboratory Manual On MYSQL For Year IV Database Students (Power and Control Engineering Stream Students)
PDF
Laboratory Manual On MYSQL For Year IV Database Students (Power and Control Engineering Stream Students)
5.introduction To MySQL
PDF
5.introduction To MySQL
mysql-data-types
PDF
mysql-data-types
DBMS Lab 3-4
PDF
DBMS Lab 3-4
MySQL Tutorial
PDF
MySQL Tutorial
Chap4 Introduction To SQL and MySQL
PDF
Chap4 Introduction To SQL and MySQL
DWPD GTU Study Material E-Notes Unit-5 03082019063134AM PDF
PDF
DWPD GTU Study Material E-Notes Unit-5 03082019063134AM PDF
Data Types
PDF
Data Types
DWPD GTU Study Material E-Notes Unit-5 22092020071825AM
PDF
DWPD GTU Study Material E-Notes Unit-5 22092020071825AM
Cs
PDF
Cs
PHP MySQL Module IV
PDF
PHP MySQL Module IV
Lec4 - Mysql - PHP
PDF
Lec4 - Mysql - PHP
PHP MySQL Create Database and Tables
PDF
PHP MySQL Create Database and Tables
MySQL
PDF
MySQL
PHP MySQL Create Table
PDF
PHP MySQL Create Table
Relational Databases and Mysql: This Work Is Licensed Under A
PDF
Relational Databases and Mysql: This Work Is Licensed Under A
Slide MySql
PDF
Slide MySql
Lecture3 PHP MySQL
PDF
Lecture3 PHP MySQL
Iwd Unit 5 Working With Database
PDF
Iwd Unit 5 Working With Database
Unit3 PHP
PDF
Unit3 PHP
WWW PHP Tutorials Info
PDF
WWW PHP Tutorials Info
SQL Labsheets
PDF
SQL Labsheets
Data Types MySQL
PDF
Data Types MySQL
PHP 13
PDF
PHP 13
My SQL - Basic Concepts - 71766
PDF
My SQL - Basic Concepts - 71766
L9 SQL
PDF
L9 SQL
Basic To Advance Tutorial of SQL
PDF
Basic To Advance Tutorial of SQL
LAB 02 Data Types. Create and Alter Table Structure: V Main Contents
PDF
LAB 02 Data Types. Create and Alter Table Structure: V Main Contents
SQL Statement
PDF
SQL Statement
PHP 09 MySQL
PDF
PHP 09 MySQL
My SQL Instagram
PDF
My SQL Instagram
Basic Steps in MySQL
PDF
Basic Steps in MySQL
Lecture 15 - MySQL - PHP 1
PDF
Lecture 15 - MySQL - PHP 1
SQL Cheat Sheet
PDF
SQL Cheat Sheet
Basics of PHP & MySQL
PDF
Basics of PHP & MySQL
06 Working With Databases
PDF
06 Working With Databases
UNIT 5-Part 1
PDF
UNIT 5-Part 1
Introduction To Databases and SQL
PDF
Introduction To Databases and SQL
L23 - Mysql 1
PDF
L23 - Mysql 1
Short Notes 1 - MySQL Commands 1 1650270538687
PDF
Short Notes 1 - MySQL Commands 1 1650270538687
Basic PHP Database MYSQL For Beginners
PDF
Basic PHP Database MYSQL For Beginners
Introduction To Mysql Server: Mysql Cluster - Provides Fault Tolerance
PDF
Introduction To Mysql Server: Mysql Cluster - Provides Fault Tolerance
Table Creation and DML Commands
PDF
Table Creation and DML Commands
Computer 3
PDF
Computer 3
C9 MySQL1
PDF
C9 MySQL1
Data Types
PDF
Data Types
Mysql
PDF
Mysql
unit 2
PDF
unit 2