PHHP & MYsql Unit 4
PHHP & MYsql Unit 4
Class Definition
class Car {
This defines a class called Car. A class is like a blueprint or template for creating objects.
The Car class will have properties (attributes) and methods (functions) associated with it.
2. Public Property
public $color;
Here, the class Car has a public property $color. In PHP, the public keyword means that
this property can be accessed directly from outside the class. This property is used to store the
color of the car.
3. Constructor Method
public function __construct($color) {
$this->color = $color;
}
So, when a Car object is created, the constructor sets the initial value for the $color
property.
This is a public method named getColor. Its purpose is to return the value of the $color
property. Since $color is a property of the class, it can only be accessed through a method
like this (if encapsulation principles are followed).
return $this->color;: This returns the value of the $color property of the current
object.
Classes, objects, methods and
properties
Object-oriented programming is a programming style in which it is
customary to group all of the variables and functions of a particular
topic into a single class. Object-oriented programming is considered to
be more advanced and efficient than the procedural style of
programming. This efficiency stems from the fact that it supports
better code organization, provides modularity, and reduces the need to
repeat ourselves. That being said, we may still prefer the procedural
style in small and simple projects. However, as our projects grow in
complexity, we are better off using the object oriented style.
classes
objects
methods
properties
You'll learn
How to create classes?
How to add properties to a class?
How to create objects from a class?
How to get and set the objects' properties?
How to add methods to a class?
If the class name contains more than one word, we capitalize each word. This is
known as upper camel case. For
example, JapaneseCars, AmericanIdol, EuropeTour, etc.
We circle the class body within curly braces. Inside the curly braces, we put our
code.
If the name contains more than one word, all of the words, except for the first
word, start with an upper case letter. For example, $color or $hasSunRoof.
A property can have a default value. For example, $color = 'beige'.
We can also create a property without a default value. See the
property $comp in the above example.
We can create more than one object from the same class.
In fact, we can create as many objects as we like from the same class,
and then give each object its own set of properties.
I say objects, and not object, because we can create as many objects
as we would like from the same class and they all will share the class's
methods and properties. See the image below:
From the same Car class, we created three individual objects with the
name of: Mercedes, Bmw, and Audi.
Although all of the objects were created from the same class and thus
have the class's methods and properties, they are still different. This is
not only, because they have different names, but also because they
may have different values assigned to their properties. For example, in
the image above, they differ by the color property - the Mercedes is
green while the Bmw is blue and the Audi is orange.
A class holds the methods and properties that are shared by all of the
objects that are created from it.
Although the objects share the same code, they can behave differently
because they can have different values assigned to them.
Note that the property name does not start with the $ sign; only the object name
starts with a $.
Result:beige
beige
For example, in order to set the color to 'blue' in the bmw object:
We can also get the company name and the color of the second car
object.
public $comp;
public $color = 'beige';
public $hasSunRoof = true;
If the name contains more than one word, all of the words, except for the first
word, start with an upper case letter. For example, helloUser() or flyPanAm().
We can approach the methods similar to the way that we approach the
properties, but we first need to create at least one object from the
class.
Here is the full code that we have written during this tutorial:
12345678
9101112131415161718192021222324252627282930313233343536373839404
142434445<?php
// Declare the class
class Car {
// properties
public $comp;
public $color = 'beige';
public $hasSunRoof = true;
// Create an instance
$bmw = new Car ();
$mercedes = new Car ();
<?php
//
class GFG {
// Function definition
public function __set($name, $value) {
echo "Setting '$name' to '$value'\n";
$this->data[$name] = $value;
}
// Function definition
public function __get($name) {
echo "Getting '$name: ";
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
$trace = debug_backtrace();
return null;
}
// Function definition
public function __isset($name) {
echo "Is '$name' set?\n";
return isset($this->data[$name]);
}
// Create an object
$obj = new GFG;
// Unset 'a'
unset($obj->a);
var_dump(isset($obj->a));
?>
Output:
Setting 'a' to '1'
Getting 'a: 1
Is 'a' set?
bool(true)
Unsetting 'a'
Is 'a' set?
bool(false)
1
?>
You can understand this with a simple real-life example. Consider the example
of human beings. You inherit characteristic features from the class ‘Humans’,
such as walking, sitting, running, eating, etc. The class ‘Humans’ inherits from
the class ‘Mammal’, these characteristic features - making the class ‘Human' a
derived class of ‘Mammal’. Furthermore, the class ‘Mammal’ gets its
characteristic features from another yet another class - ‘Animal’. This makes the
class ’Mammal’ a derived class of the ‘Animal’ class; also making the ‘Animal’
class a base class.
Inheritance in PHP
Inheritance provides you with many benefits that make PHP programming a lot
more convenient. One such benefit is code reusability. Reusability allows you to
generate clean code and the replication of code gets reduced to almost zero.
Reusing existing codes serves various advantages. It saves time, cost, effort, and
increases a program’s reliability. Moreover, the program becomes intuitive.
PHP offers mainly three types of inheritance based on their functionality. These
three types are as follows:
Depicted below is the syntax that is used to extend a base class in PHP.
class derived_class_name extends base_class_name {
base_class_name: It specifies the name of the base or the parent class from
which the child class is inheriting its properties. A base class is also known as
a parent class because all the classes that are termed as derived classes or
child classes inherit their properties from the base class. There can be one or
more base classes in a program, depending upon the type of inheritance. For
instance, in a single-level inheritance, there will be one base class for one
child class, but in a multilevel inheritance, one child class can inherit from
over one base class in more than one level.
The access modifier (private, public, or protected) used in the definition of the
member functions and data members of the derived class specifies the mode
with which the features of the base class are derived. The access modifier
controls where and how the data members and member functions of a base class
can be inherited by the child classes. These access modifiers are used to restrict
the access of the base class from the child class to encapsulate the data. This is
popularly known as data hiding.
Public access modifier gives the least privacy to the attributes of the base class.
If the access modifier is public, it means that the derived class can access the
public and protected members of the base class but not the private members of
the base class.
public $var_name;
<?php
class Jewellery {
echo $this->price;
echo PHP_EOL;
function print(){
echo $this->price;
echo PHP_EOL;
// derived class.
echo $obj->price;
echo PHP_EOL;
$obj->printMessage();
$obj->print();
?>
Private:
private $var_name;
Although the direct accessibility of a private member is not possible, you can
access them indirectly using public member functions in the class. If the private
members are accessed by a public member in a class, then any child class
accessing this public function can also access that private member.
<?php
class Jewellery {
function printPrice()
echo $this->price;
}
// derived class
$obj->show();
$obj->printPrice();
?>
Protected:
Protected access modifier provides an intermediate privacy level to the
members of a class. If the access specifier is protected, this means that the
derived class can access the public and protected members of the base class.
The protected members of a base class can be accessed within that class and by
its child classes.
protected $var_name;
<?php
class Jewellery {
function total()
echo PHP_EOL;
function printInvoice()
$tax = 100;
echo PHP_EOL;
$obj->total();
$obj->printInvoice();
?>
However, a child class can also have its own methods and properties. Apart
from the members of the base class, a derived class can have as many data
members and methods as you want. A derived class is just like any other class,
with the benefit of having access to some other methods and properties of a base
class. This is what inheritance is all about.
The following program illustrates a child class having access to the properties of
its base class along with its methods and properties:
<?php
class base_class {
// data member of the base class
echo $this->data_mem;
function child_func()
echo $this->data_mem;
// derived class
$obj= new child_class;
$obj->member_func();
$obj->child_func();
?>
Single Inheritance
Single inheritance is the most basic and simple inheritance type. As the name
suggests, in a single inheritance, there is only one base class and one sub or
derived class. It directly inherits the subclass from the base class.
The following program illustrates single level inheritance in PHP:
<?php
class Jewellery {
echo 'This is base class: Jewellery & name of jewellery is: ' . $name .
PHP_EOL;
echo 'This is child class: Necklace & name of jewellery is: ' . $name .
PHP_EOL;
$f = new Jewellery();
$s = new Necklace();
$f->printName('Ring');
$s->printName('Necklace');
?>
Multilevel Inheritance
<?php
class Jewellery {
// creating object of
$obj->priceList();
?>
Hierarchical Inheritance
<?php
// base class named "Jewellery"
class Jewellery {
// creating objects of
// derived classes
$n = new Necklace();
$b = new Bracelet();
?>
Protected Access Modifier in PHP
<?php
class Jewellery {
$obj->show();
?>
In the above program, an instance of the derived class tries to call a protected
member function of its base class outside both of the classes. That’s why the
program is throwing an error.
This issue can be solved using a public method. Since a protected member can
be directly accessed inside the derived class, so calling the protected member in
a public method of the derived class makes it possible to achieve the task of
accessing the protected member indirectly.
<?php
class Jewellery {
}
}
$this->display();
$obj->show();
?>
Overriding Inherited Methods in PHP
<?php
class base_class {
}
}
$obj->show();
?>
In the program above, both the base class (i.e. base_class) and the derived class
(i.e. derived_class) have a function called “show”. If an instance of the derived
class calls the show() function, then PHP will call the show() function of the
derived call. This is because the derived_class overrides the show() of the
base_class with its own show() method. If an instance of the base class uses the
show() method, then there will be no overriding of the method.
In PHP, the final keyword serves different purposes depending upon whether
it’s used with a class or a method.
The final keyword used with a class: The final keyword with a class, serves
the purpose of preventing inheritance. If a class is declared final, using the
keyword “final”, then inheriting that class will cause the program to throw an
error. This can be useful in a case when you don’t want a class and its
members to be accessed anywhere else in the program.
The following program illustrates the concept of the “final” keyword with
classes in PHP:
Note: This code will throw an error as we are trying to inherit a final class.
<?php
function print() {
echo "I am the Jewellery class function.";
function show() {
$obj->show();
?>
The final keyword used with a method: The final keyword when used with a
method, serves the purpose of preventing method overriding. If a method has
been declared final, using the “final” keyword, then another function with the
same name and same parameters can not be defined in a derived class.
Calling such a function will cause the program to throw an error.
The following programs illustrate the concept of the “final” keyword with
methods in PHP:
Without the final keyword (will produce output, but will cause method
overriding)
<?php
class Jewellery {
function printMessage() {
function printMessage() {
$ob->printMessage();
?>
With the final keyword. (WIll throw an error, to prevent method overriding).
<?php
class Jewellery {
function printMessage() {
}
$ob = new testClass;
$ob->printMessage();
?>
Multiple inheritance is a type of inheritance in which one class can inherit the
properties from more than one parent class. In this type of inheritance, there is
one derived class, that is derived from multiple base classes. This is one of the
most important and useful concepts provided in the object-oriented paradigm
and serves the purpose wherein you want one class to inherit different types of
properties (which are in different classes).
For example, consider a class called parrot. Now, since a parrot is a bird, and it
can also be a pet or simply a living creature, so, the class parrot can serve
different properties. So, using multiple inheritance, the parrot class can inherit
the properties of all three classes bird, pet, and living_creature.
Many programming languages do not support multiple inheritance directly
like Java and PHP. However, PHP provides some ways to implement multiple
inheritance in your programs. In the PHP programming language, multiple
inheritance is achieved by using two ways:
Traits:
The traits can be used to implement the concept of multiple inheritance in PHP.
Syntax
...
...
// base_class functions
}
The following program illustrates the usage of traits to implement multiple
inheritance:
<?php
// declare a class
class Bird {
// declare a trait
trait Pet {
use Pet;
$test->display();
$test->show();
$test->msg();
?>
Interfaces:
Interfaces are used when there are objects that share the same functionality, but
you don’t want the objects to know about each other. In other words, an
interface provides contracts for the objects, without knowing anything else
about one another.
// to use interface
<?php
// define a class
class Bird {
// declare an interface
interface Pet {
function insidePet() {
$obj->insideBird();
$obj->insidePet();
$obj->insideParrot();
?>
Importance of Inheritance in PHP
In PHP, constructors and destructors are special methods that are used in
object-oriented programming (OOP). They help initialize objects when they
are created and clean up resources when the object is no longer needed.
These methods are part of the class lifecycle.
In this article, we will discuss what constructors and destructors are and
how to use them.
What are Constructors in PHP?
A constructor is a special function or method in a class that is automatically
called when an object of the class is created. The constructor is mainly
used for initializing the object, i.e., setting the initial state of the object by
assigning values to properties.
Syntax:
<?php
class ClassName {
public function __construct() {
// Constructor code here
}
}
?>
Now, let us understand with the help of the example:
<?php
class Car {
public $model;
public $color;
// Constructor
public function __construct($model, $color) {
$this->model = $model;
$this->color = $color;
}
Output
Model: Tesla, Color: Red
In this example:
The constructor __construct() is used to initialize the properties $model
and $color when an object of the Car class is created.
When the object $myCar is created, the constructor is called
automatically with "Tesla" and "Red" passed as arguments, thus
initializing the car's properties.
The display() method is used to print the car details.
What are Destructors in PHP?
A destructor is a special method in PHP that is automatically called when
an object is destroyed or goes out of scope. It is mainly used for cleaning
up or releasing resources that the object might have acquired during its
lifetime, such as closing file handles or database connections.
Syntax:
<?php
class ClassName {
public function __destruct() {
// Destructor code here
}
}
?>
<?php
class Database {
public $connection;
// Constructor to initialize the connection
public function __construct($hostname) {
$this->connection = "Connected to database at $hostname";
echo $this->connection;
}
<?php
class Animal {
public $name;
$this->name = $name;
unset($dog);
?>
Output
Rex is an animal.
Rex is a dog.
Rex is no longer a dog.
Animal Rex is destroyed.
In this example:
The parent class, Animal, has its constructor to set the name and
display a message.
The child class Dog calls the parent constructor using
parent::__construct($name).
Both the constructor and destructor of the parent and child classes are
executed.
Best Practices for Constructors and Destructors
Constructors
Always initialize the properties of the object inside the constructor.
If you need to pass arguments to the constructor, make sure to
document them.
Constructors should not contain logic that affects program flow (e.g.,
database queries, heavy processing).
Destructors
Use destructors to release any resources that your object may have
acquired, such as database connections, file handlers, or network
connections.
Avoid using complex logic in destructors, as they are mainly intended for
cleanup.
Destructors should not raise exceptions or output data (unless
necessary).
Constructors vs Destructors
Constructors Destructors
It is called at the time the object is It is called automatically at the time of object
created. deletion.
Conclusion
Constructors and Destructor methods are very useful as they make very c
tasks easier during coding. These encourage re-usability of code without
unnecessary repetition. Both of them are implicitly called by the compiler,
even though they are not defined in the class.
PHP Form Handling
Last Updated : 14 Apr, 2025
<html>
<body>
<table>
<tr>
<td>Full Name:</td>
</tr>
<tr>
<td>Email Address:</td>
</tr>
<tr>
<td>Age:</td>
</tr>
<tr>
<td>Feedback:</td>
</tr>
<tr>
<td>Gender:</td>
<td>
</td>
</tr>
<tr>
</tr>
</table>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['fullname'])) {
$fullname = htmlspecialchars($_POST['fullname']);
if (isset($_POST['user_email'])) {
$user_email = htmlspecialchars($_POST['user_email']);
$user_age = htmlspecialchars($_POST['user_age']);
if (isset($_POST['user_feedback'])) {
$user_feedback = htmlspecialchars($_POST['user_feedback']);
if (isset($_POST['user_gender'])) {
$user_gender = htmlspecialchars($_POST['user_gender']);
}
}
?>
</body>
</html>
What is MySQL?
Last Updated : 28 Apr, 2025
What is MySQL?
In this article, we will explore the importance of MySQL with its uses and
discover why it is so important in databases.
Key Features in MySQL
MySQL is a popular choice for managing relational databases for several
reasons:
Open-Source: MySQL is free and open-source, allowing modification
and distribution.
High Performance: It offers fast data retrieval and processing for large
datasets.
ACID Compliance: Ensures data integrity and reliability, especially with
InnoDB storage.
Scalability: Supports large databases and high traffic with features like
partitioning and clustering.
Multiple Storage Engines: Offers different storage engines (e.g.,
InnoDB, MyISAM) for flexible use.
Replication: Supports master-slave replication for data redundancy and
high availability.
Security Features: Provides user authentication, SSL encryption, and
secure data storage options.
Who Uses MySQL
MySQL is a widely-used relational database management system
(RDBMS) that caters to various user groups, from small businesses to
large enterprises. Here's a look at who uses MySQL:
Small to Medium-Sized Businesses (SMBs): MySQL is popular
among SMBs due to its cost-effectiveness, ease of use, and flexibility.
These businesses leverage MySQL for managing their customer data,
sales transactions, and other operational databases.
Large Enterprises: Many large organizations use MySQL for its
scalability and reliability. Companies like Facebook, Google, and Adobe
rely on MySQL to handle large-scale databases and high-traffic
applications.
Web Developers: MySQL is a favorite among web developers because
it integrates seamlessly with popular web development technologies
such as PHP and JavaScript. It powers many websites and web
applications, from blogs to e-commerce platforms.
Educational Institutions: MySQL is frequently used in academic
settings for teaching database management and SQL skills. Its open-
source nature makes it a cost-effective choice for educational purposes.
Applications of MySQL
MySQL has used in various applications across a wide range of industries
and domains, because of to its versatility, reliability, and performance. Here
are some common applications :
E-commerce: MySQL is extensively used in e-commerce platforms for
managing product catalogs, customer data, orders, and transactions.
Content Management Systems (CMS): Many popular CMS platforms
rely on MySQL as their backend database to store website
content, user profiles, comments, and configuration settings.
Financial Services: MySQL is employed in financial applications,
including banking systems, payment processing platforms, and
accounting software, to manage transactional data, customer
accounts, and financial records.
Healthcare: MySQL is used in healthcare applications for storing and
managing patient records, medical histories, treatment plans, and
diagnostic information.
Social Media: MySQL powers the backend databases of many social
media platforms, including user profiles, posts, comments, likes, and
connections.
The Cloud and the Future of MySQL
The cloud has significantly influenced the evolution of MySQL, shaping its
future in several ways:
Cloud Integration:
Managed Services: Cloud providers such as Amazon Web Services
(AWS), Google Cloud Platform (GCP), and Microsoft Azure offer
managed MySQL services (e.g., Amazon RDS, Google Cloud SQL) that
simplify database management, scaling, and maintenance.
Scalability: Cloud environments enable dynamic scaling of MySQL
databases, allowing users to adjust resources based on demand without
significant upfront investments.
Enhanced Features:
High Availability: Cloud-based MySQL solutions often come with built-
in high availability and disaster recovery options, improving resilience
and uptime.
Automatic Backups: Cloud services provide automated backup
solutions, ensuring data integrity and ease of recovery.
Future Trends:
Hybrid Cloud Deployments: Organizations are increasingly adopting
hybrid cloud strategies, integrating MySQL databases across on-
premises and cloud environments for greater flexibility and performance.
Advanced Analytics: The integration of MySQL with cloud-based
analytics and machine learning platforms is likely to grow, enabling more
advanced data analysis and insights.
Serverless Architectures: As serverless computing continues to
evolve, MySQL may adapt to serverless environments, offering more
efficient and cost-effective solutions for database management.
Difference Between MySQL and SQL
MySQL SQL
Overview
MySQL offers various unique features to its users and one such feature is its ability
to handle various types of data. Data types are a building block of any
programming language. In MySQL, data types determine the type of value you can
store in a column of a table so it is very important to understand the basics of the
vast variety of data types that MySQL offers.
In MySQL, there are several data types, including string, numeric, date and time,
spatial, and JSON. In this article, we will provide an overview of each of these data
types, including their description, default values, storage requirements, and how to
choose the right type for a column.
Introduction
One of the key features of MySQL is its ability to handle various data types. Data
types define the type of data that can be stored in a particular column of a table.
Each data type has its characteristics, such as size, precision, and range, which
determine the kind of data that can be stored in that column and that is why it is
very important to choose the right data type for our table columns. When we create
a table, we need to specify a name for the table and a data type that not only tells us
and defines the kind of data that can be stored in the table column but also tells us
what influence it may have on the database efficiency and performance.
We can define the data type in MySQL with the following characteristics:
We can broadly define the different data types in MySQL in five categories.
The MySQL String Data Types can be divided into these 6 categories:
TEXT
BLOB
CHAR and VARCHAR
BINARY and VARBINARY
ENUM
SET
The following table summarizes each string data type in MySQL and will give you
a basic understanding of each of them.
Data Type Maximum Size Description
Stores fixed-length strings
with a length of up to 255
characters. If the length is
CHAR(size) 255 characters
less than 255, then the
remaining space is padded
with spaces.
Stores variable-length strings
VARCHAR(size) 255 characters with a length of up
to 255 characters.
Stores a small text string
TINYTEXT(size) 255 characters with a length of up to 255
characters.
Stores a large text string with
TEXT(size) 65,535 characters a length of up to 65,535
characters.
Stores a medium text string
MEDIUMTEXT(size) 16,777,215 characters with a length of up to
16,777,215 characters.
Stores a very large text string
LONGTEXT(size) 4GB or 4,294,967,295 characters with a length of up to 4GB or
4,294,967,295 characters.
Stores fixed-length binary
strings with a length of up
to 255 characters. If the
BINARY(size) 255 characters
length is less than 255, then
the remaining space is
padded
Stores variable-length binary
VARBINARY(size) 255 characters strings with a length of up to
255 characters.
Stores a value from a
predefined list of values.
ENUM 65,535 values Each value is assigned a
numeric index from 1 to
65,535.
Stores one or more values
SET 64 members from a predefined list of up
to 64 members.
The TEXT data type has a storage capacity that ranges from 1 byte to 4 GB and
contrary to numeric data types, the TEXT data type in the table column does not
require you to provide a length.
The four TEXT data types in MySQL are TINYTEXT, TEXT, MEDIUMTEXT,
and LONGTEXT.
BLOB Datatype
The BLOB data types are binary strings as opposed to the non-binary string data
type, TEXT. Binary media files such as audio or video links, photos, or files, can
be stored using the BLOB data type in MySQL, which stands for a binary large
object data type.
In MySQL, non-binary strings with fixed lengths up to 255 characters can store in
the CHAR data type, on the other hand, non-binary strings with variable lengths up
to 65535 characters can be stored in the VARCHAR data type.
When adding a column, you must specify a size parameter in characters (in
brackets) for both data types. The size option specifies the minimum and maximum
column sizes for CHAR and VARCHAR data types, respectively.
BINARY and VARBINARY data types are quite similar to the CHAR and
VARCHAR data types, but they differ in a few ways. Binary strings are stored in
the variables BINARY and VARBINARY, whose length is expressed in bytes.
ENUM Datatype
MySQL ENUM data types represent the strings with enumeration values. With
ENUM, you can specify a list of predetermined values and then select from it. You
will receive an empty string if you add an invalid value that is not on the list.
SET datatype
The MySQL SET data types enable you to store one or more values that you
provided in a list of preset values when creating a table, separated by commas.
TINYINT
SMALLINT
INT
MEDIUMINT
BIGINT
DECIMAL
FLOAT
DOUBLE
BIT
BOOL
BOOLEAN
T
he following table summarizes each numeric data type in MySQL and will
give you a basic understanding of each of them.
Data
Syntax Description
Type
A small-sized integer that can be signed or unsigned. If signed, the
allowable range is
from −2(n−1)−2(n−1) to 2(n−1)−12(n−1)−1. If unsigned,
the allowable range is from 0 to 2n−10 to 2n−1. The "n"
parameter specifies the maximum display width in digits and can
range from 1 to 3. TINYINT requires 1 byte for storage.
A larger-sized integer that can be signed or
unsigned. If signed, the allowable range is
from −2(n−1) to 2(n−1)−1
MEDIUMINT MEDIUMINT(n)
2(n−1)−1. If unsigned, the allowable range is
TINYIN TINYINT(n from 0 to 2n−10 to 2n−1. The "n" parame
T ) specifies the maximum display width in digits an
can range from 1 to 9. MEDIUMINT
requires 3 bytes for storage.
A normal-sized integer that can be signed or
unsigned. If signed, the allowable range is
from −2(n−1) to 2(n−1)−1
INT INT(n)
2(n−1)−1. If unsigned, the allowable range is
from 0 to 2n−10 to 2n−1. The "n" parame
specifies the maximum display width in digits an
can range from 1 to 11. INT requires
storage.
SMALLI SMALLIN A medium-sized integer that can be signed or unsigned. If signed, the
NT T(n) allowable range is from -2^(n-1) to
Data
Syntax Description
Type
A large-sized integer that can be signed or unsigned. If signed, the
allowable range is from −2(n−1) to 2(n−1)−1−2(n−1) to 2(n−1)−1. If
BIGINT BIGINT(n) unsigned, the allowable range is from 0 to 2n−10 to 2n−1. The "n"
parameter specifies the maximum display width in digits and can
range from 1 to 20. BIGINT requires 8 bytes for storage.
A floating-point number that cannot be unsigned. The "m" parameter
specifies the maximum display width in digits and the "d" parameter
FLOAT(m,
FLOAT specifies the number of digits after the decimal point. If not specified,
d)
"m" defaults to 10, and "d" defaults to 2. FLOAT can store up
to 24 decimal places and requires 4 bytes for storage.
UNSIGNED integer data types allow only zero and positive numbers, while
SIGNED integer data types allow zero, positive, and negative numbers.
Boolean data types, unlike integer data types, can only store true or false values. In
MySQL, boolean values are converted into integer data types (TINYINT),
where 0 represents false and 1 represents true.
Double data types are used to represent double-precision numeric values, which are
also approximate but require 8 bytes for storage. Similar to float data types, they
can be set as either SIGNED or UNSIGNED and have a minimum and maximum
storage size depending on their attribute.
DATE
TIME
DATETIME
TIMESTAMP
YEAR
The following table summarizes the usage, data type format, and range of each
type: