SlideShare a Scribd company logo
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
National Diploma in Information and Communication Technology
PHP :3-PHP-CONNECT-TO-MySQL>
K72C001M07 - Web Programming
Y. Achchuthan
Department of Information & Communication Technology,
Sri Lanka – German Training Institute
11/23/2018 3-PHP-CONNECT-TO-MySQL 1
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
What is MySQL?
• MySQL is a database system used on the web
• MySQL is a database system that runs on a server
• MySQL is ideal for both small and large applications
• MySQL is very fast, reliable, and easy to use
• MySQL uses standard SQL
• MySQL compiles on a number of platforms
• MySQL is free to download and use
• MySQL is developed, distributed, and supported by Oracle
Corporation
11/23/2018 3-PHP-CONNECT-TO-MySQL 2
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Connect to MySQL
• Open a Connection to MySQL
• Syantax
$con = mysqli_connect(host,username,password,dbname,port,socket);
Return Value: Returns an object representing the connection to the MySQL
server
11/23/2018 3-PHP-CONNECT-TO-MySQL 3
Parameter Description
host Optional. Specifies a host name or an IP address
username Optional. Specifies the MySQL username
password Optional. Specifies the MySQL password
dbname Optional. Specifies the default database to be used
port Optional. Specifies the port number to attempt to connect to the MySQL
server
socket Optional. Specifies the socket or named pipe to be used
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Closing a Connection
• Close the created database connection as follows
mysql_close($con);
11/23/2018 3-PHP-CONNECT-TO-MySQL 4
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example - mysqli_connect()
//config.php
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','');
$conn=mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME)
;
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " .
mysqli_connect_error();
}
echo "Connected successfully";
11/23/2018 3-PHP-CONNECT-TO-MySQL 5
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
mysqli_query() Function
• Perform queries against the database:
• Syntax
mysqli_query(connection,query,resultmode);
11/23/2018 3-PHP-CONNECT-TO-MySQL 6
Parameter Description
connection Required. Specifies the MySQL connection to use
query Required. Specifies the query string
resultmode Optional. A constant. Either:
•MYSQLI_USE_RESULT (Use this if we have to retrieve large amount of
data)
•MYSQLI_STORE_RESULT (This is default)
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Create a MySQL Database
$sql = "CREATE DATABASE NVQ5";
if (mysqli_query($conn, $sql)) {
echo "Database created successfully";
} else {
echo "Error creating database: " .
mysqli_error($conn);
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 7
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Create MySQL Tables
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if (mysqli_query($conn, $sql)) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " .
mysqli_error($conn);
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 8
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Notes on the table above
• NOT NULL - Each row must contain a value for that column, null
values are not allowed
• DEFAULT value - Set a default value that is added when no other
value is passed
• UNSIGNED - Used for number types, limits the stored data to positive
numbers and zero
• AUTO INCREMENT - MySQL automatically increases the value of the
field by 1 each time a new record is added
• PRIMARY KEY - Used to uniquely identify the rows in a table. The
column with PRIMARY KEY setting is often an ID number, and is often
used with AUTO_INCREMENT
11/23/2018 3-PHP-CONNECT-TO-MySQL 9
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Insert Data Into MySQL
After a database and a table have been created, we can start adding
data in them.
• Here are some syntax rules to follow:
• The SQL query must be quoted in PHP
• String values inside the SQL query must be quoted
• Numeric values must not be quoted
• The word NULL must not be quoted
Note: I f a column is AUTO_INCREMENT (like the "id" column) or
TIMESTAMP (like the "reg_date" column), it is no need to be specified
in the SQL query; MySQL will automatically add the value.
11/23/2018 3-PHP-CONNECT-TO-MySQL 10
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Insert Data Into MySQL
$sql = "INSERT INTO MyGuests (firstname,
lastname, email) VALUES ('John', 'Doe',
'john@example.com')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" .
mysqli_error($conn);
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 11
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Insert Multiple Records Into MySQL
$sql = "INSERT INTO MyGuests (firstname, lastname,
email)
VALUES ('John', 'Doe', 'john@example.com');";
$sql .= "INSERT INTO MyGuests (firstname,
lastname,email)
VALUES ('Mary', 'Moe', 'mary@example.com');";
$sql .= "INSERT INTO MyGuests (firstname,
lastname,email)
VALUES ('Julie', 'Dooley', 'julie@example.com')";
if (mysqli_multi_query($conn, $sql)) {
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 12
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Select Data From a MySQL
$sql = "SELECT * FROM MyGuests";
//$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
//var_dump($row);
echo "id: " . $row["id"]. " - Name: " .
$row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 13
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Delete Data From a MySQL
$sql = "DELETE FROM MyGuests WHERE id=3";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " .
mysqli_error($conn);
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 14
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Update Data In a MySQL
$sql = "UPDATE MyGuests SET lastname='Mugund'
WHERE id=9";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " .
mysqli_error($conn);
}
11/23/2018 3-PHP-CONNECT-TO-MySQL 15
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Limit Data Selections From a MySQL
$sql = "SELECT * FROM MyGuests ORDER BY id ASC LIMIT
10 OFFSET 15";
//$sql = "SELECT * FROM MyGuests ORDER BY id ASC
LIMIT 10 OFFSET 10";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " .
$row["firstname"]. " " . $row["lastname"].
"<br>";
}
} else {
echo "0 results";
}
Note: The SQL query above says "return only 10 records, start on record 16 (OFFSET 15)":
11/23/2018 3-PHP-CONNECT-TO-MySQL 16
Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Reference
www.w3schools.com
www.php.net
www.slgti.com
Friday, November 23, 2018 17

More Related Content

Similar to 3 php-connect-to-my sql (20)

PPTX
Connecting to my sql using PHP
Nisa Soomro
 
PDF
Develop Python Applications with MySQL Connector/Python
Jesper Wisborg Krogh
 
PPT
Mysql
guest817344
 
PDF
Using php with my sql
salissal
 
PPT
Php classes in mumbai
aadi Surve
 
PDF
MySQL server security
Damien Seguy
 
PDF
Agile Data Science 2.0
Russell Jurney
 
PPT
SQLSecurity.ppt
CNSHacking
 
PPT
SQLSecurity.ppt
LokeshK66
 
PPTX
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
PDF
NoSQL meets Microservices - Michael Hackstein
distributed matters
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PDF
Agile Data Science
Russell Jurney
 
PPT
Php and MySQL Web Development
w3ondemand
 
DOCX
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 
PDF
MySQL NoSQL JSON JS Python "Document Store" demo
Keith Hollman
 
PPT
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
SenzotaSemakuwa
 
PDF
Agile Data Science 2.0
Russell Jurney
 
PDF
DEFCON 23 - Lance buttars Nemus - sql injection on lamp
Felipe Prado
 
PDF
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 
Connecting to my sql using PHP
Nisa Soomro
 
Develop Python Applications with MySQL Connector/Python
Jesper Wisborg Krogh
 
Using php with my sql
salissal
 
Php classes in mumbai
aadi Surve
 
MySQL server security
Damien Seguy
 
Agile Data Science 2.0
Russell Jurney
 
SQLSecurity.ppt
CNSHacking
 
SQLSecurity.ppt
LokeshK66
 
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
NoSQL meets Microservices - Michael Hackstein
distributed matters
 
Database Connectivity in PHP
Taha Malampatti
 
Agile Data Science
Russell Jurney
 
Php and MySQL Web Development
w3ondemand
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 
MySQL NoSQL JSON JS Python "Document Store" demo
Keith Hollman
 
Lect_04b_PhpMysqlKEY PERFORMANCE INDICATOR FOR ICT-UNIT (new).ppt
SenzotaSemakuwa
 
Agile Data Science 2.0
Russell Jurney
 
DEFCON 23 - Lance buttars Nemus - sql injection on lamp
Felipe Prado
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 

More from Achchuthan Yogarajah (11)

PPTX
Managing the design process
Achchuthan Yogarajah
 
PPTX
intoduction to network devices
Achchuthan Yogarajah
 
PPTX
basic network concepts
Achchuthan Yogarajah
 
PPTX
4 php-advanced
Achchuthan Yogarajah
 
PPTX
PHP Form Handling
Achchuthan Yogarajah
 
PPTX
PHP-introduction
Achchuthan Yogarajah
 
PPTX
Introduction to Web Programming
Achchuthan Yogarajah
 
PPTX
Language Localisation of Tamil using Statistical Machine Translation - ICTer2015
Achchuthan Yogarajah
 
PPTX
PADDY CULTIVATION MANAGEMENT SYSTEM
Achchuthan Yogarajah
 
PPTX
Statistical Machine Translation for Language Localisation
Achchuthan Yogarajah
 
PDF
Greedy Knapsack Problem - by Y Achchuthan
Achchuthan Yogarajah
 
Managing the design process
Achchuthan Yogarajah
 
intoduction to network devices
Achchuthan Yogarajah
 
basic network concepts
Achchuthan Yogarajah
 
4 php-advanced
Achchuthan Yogarajah
 
PHP Form Handling
Achchuthan Yogarajah
 
PHP-introduction
Achchuthan Yogarajah
 
Introduction to Web Programming
Achchuthan Yogarajah
 
Language Localisation of Tamil using Statistical Machine Translation - ICTer2015
Achchuthan Yogarajah
 
PADDY CULTIVATION MANAGEMENT SYSTEM
Achchuthan Yogarajah
 
Statistical Machine Translation for Language Localisation
Achchuthan Yogarajah
 
Greedy Knapsack Problem - by Y Achchuthan
Achchuthan Yogarajah
 
Ad

Recently uploaded (20)

PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
community health nursing question paper 2.pdf
Prince kumar
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Ad

3 php-connect-to-my sql

  • 1. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology National Diploma in Information and Communication Technology PHP :3-PHP-CONNECT-TO-MySQL> K72C001M07 - Web Programming Y. Achchuthan Department of Information & Communication Technology, Sri Lanka – German Training Institute 11/23/2018 3-PHP-CONNECT-TO-MySQL 1
  • 2. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology What is MySQL? • MySQL is a database system used on the web • MySQL is a database system that runs on a server • MySQL is ideal for both small and large applications • MySQL is very fast, reliable, and easy to use • MySQL uses standard SQL • MySQL compiles on a number of platforms • MySQL is free to download and use • MySQL is developed, distributed, and supported by Oracle Corporation 11/23/2018 3-PHP-CONNECT-TO-MySQL 2
  • 3. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Connect to MySQL • Open a Connection to MySQL • Syantax $con = mysqli_connect(host,username,password,dbname,port,socket); Return Value: Returns an object representing the connection to the MySQL server 11/23/2018 3-PHP-CONNECT-TO-MySQL 3 Parameter Description host Optional. Specifies a host name or an IP address username Optional. Specifies the MySQL username password Optional. Specifies the MySQL password dbname Optional. Specifies the default database to be used port Optional. Specifies the port number to attempt to connect to the MySQL server socket Optional. Specifies the socket or named pipe to be used
  • 4. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Closing a Connection • Close the created database connection as follows mysql_close($con); 11/23/2018 3-PHP-CONNECT-TO-MySQL 4
  • 5. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Example - mysqli_connect() //config.php define('DB_HOST','localhost'); define('DB_USER','root'); define('DB_PASS',''); define('DB_NAME',''); $conn=mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME) ; if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } echo "Connected successfully"; 11/23/2018 3-PHP-CONNECT-TO-MySQL 5
  • 6. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology mysqli_query() Function • Perform queries against the database: • Syntax mysqli_query(connection,query,resultmode); 11/23/2018 3-PHP-CONNECT-TO-MySQL 6 Parameter Description connection Required. Specifies the MySQL connection to use query Required. Specifies the query string resultmode Optional. A constant. Either: •MYSQLI_USE_RESULT (Use this if we have to retrieve large amount of data) •MYSQLI_STORE_RESULT (This is default)
  • 7. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Create a MySQL Database $sql = "CREATE DATABASE NVQ5"; if (mysqli_query($conn, $sql)) { echo "Database created successfully"; } else { echo "Error creating database: " . mysqli_error($conn); } 11/23/2018 3-PHP-CONNECT-TO-MySQL 7
  • 8. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Create MySQL Tables $sql = "CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP )"; if (mysqli_query($conn, $sql)) { echo "Table MyGuests created successfully"; } else { echo "Error creating table: " . mysqli_error($conn); } 11/23/2018 3-PHP-CONNECT-TO-MySQL 8
  • 9. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Notes on the table above • NOT NULL - Each row must contain a value for that column, null values are not allowed • DEFAULT value - Set a default value that is added when no other value is passed • UNSIGNED - Used for number types, limits the stored data to positive numbers and zero • AUTO INCREMENT - MySQL automatically increases the value of the field by 1 each time a new record is added • PRIMARY KEY - Used to uniquely identify the rows in a table. The column with PRIMARY KEY setting is often an ID number, and is often used with AUTO_INCREMENT 11/23/2018 3-PHP-CONNECT-TO-MySQL 9
  • 10. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Insert Data Into MySQL After a database and a table have been created, we can start adding data in them. • Here are some syntax rules to follow: • The SQL query must be quoted in PHP • String values inside the SQL query must be quoted • Numeric values must not be quoted • The word NULL must not be quoted Note: I f a column is AUTO_INCREMENT (like the "id" column) or TIMESTAMP (like the "reg_date" column), it is no need to be specified in the SQL query; MySQL will automatically add the value. 11/23/2018 3-PHP-CONNECT-TO-MySQL 10
  • 11. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Insert Data Into MySQL $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', '[email protected]')"; if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } 11/23/2018 3-PHP-CONNECT-TO-MySQL 11
  • 12. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Insert Multiple Records Into MySQL $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', '[email protected]');"; $sql .= "INSERT INTO MyGuests (firstname, lastname,email) VALUES ('Mary', 'Moe', '[email protected]');"; $sql .= "INSERT INTO MyGuests (firstname, lastname,email) VALUES ('Julie', 'Dooley', '[email protected]')"; if (mysqli_multi_query($conn, $sql)) { echo "New records created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } 11/23/2018 3-PHP-CONNECT-TO-MySQL 12
  • 13. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Select Data From a MySQL $sql = "SELECT * FROM MyGuests"; //$sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { //var_dump($row); echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } } else { echo "0 results"; } 11/23/2018 3-PHP-CONNECT-TO-MySQL 13
  • 14. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Delete Data From a MySQL $sql = "DELETE FROM MyGuests WHERE id=3"; if (mysqli_query($conn, $sql)) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . mysqli_error($conn); } 11/23/2018 3-PHP-CONNECT-TO-MySQL 14
  • 15. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Update Data In a MySQL $sql = "UPDATE MyGuests SET lastname='Mugund' WHERE id=9"; if (mysqli_query($conn, $sql)) { echo "Record updated successfully"; } else { echo "Error updating record: " . mysqli_error($conn); } 11/23/2018 3-PHP-CONNECT-TO-MySQL 15
  • 16. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Limit Data Selections From a MySQL $sql = "SELECT * FROM MyGuests ORDER BY id ASC LIMIT 10 OFFSET 15"; //$sql = "SELECT * FROM MyGuests ORDER BY id ASC LIMIT 10 OFFSET 10"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } } else { echo "0 results"; } Note: The SQL query above says "return only 10 records, start on record 16 (OFFSET 15)": 11/23/2018 3-PHP-CONNECT-TO-MySQL 16
  • 17. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology Reference www.w3schools.com www.php.net www.slgti.com Friday, November 23, 2018 17