SlideShare ist ein Scribd-Unternehmen logo
1 von 52
MySQL Databases with PHP
PHP Programming with MySQL
2
Objectives
 Connect to MySQL from PHP
 Work with MySQL databases using PHP
 Create, modify, and delete MySQL tables with PHP
 Use PHP to manipulate MySQL records
 Use PHP to retrieve database records
3
Connecting to MySQL with PHP
 PHP has the ability to access and manipulate any database
that is ODBC compliant
 PHP includes functionality that allows you to work directly with
different types of databases, without going through ODBC
 PHP supports SQLite, database abstraction layer functions,
and PEAR DB
4
Opening and Closing a MySQL Connection
 Open a connection to a MySQL database server with the
mysql_connect() function
 The mysql_connect() function returns a positive integer if it connects to
the database successfully or FALSE if it does not
 Assign the return value from the mysql_connect() function to a variable
that you can use to access the database in your script
5
Opening and Closing a MySQL Connection (continued)
 The syntax for the mysql_connect()
function is:
$connection = mysql_connect("host" [, "user",
"password"]);
 The host argument specifies the host name where your MySQL
database server is installed
 The user and password arguments specify a MySQL account name
and password
6
Opening and Closing a MySQL
Connection (continued)
 The database connection is assigned to the $DBConnect
variable
$DBConnect = mysql_connect("localhost",
"dongosselin ", "rosebud");

Close a database connection using the mysql_close()
function
mysql_close($DBConnect);
7
Opening and Closing a MySQL
Connection (continued)
8
Opening and Closing a MySQL
Connection (continued)
MySQLInfo.php in a Web browser
9
Selecting a Database
 The syntax for the mysql_select_db() function is:
mysql_select_db(database [, connection]);
 The function returns a value of TRUE if it successfully selects a database
or FALSE if it does not
 For security purposes, you may choose to use an include file to connect to
the MySQL server and select a database
10
Reporting MySQL Errors
 Reasons for not connecting to a database server include:
 The database server is not running
 Insufficient privileges to access the data source
 Invalid username and/or password
Reporting MySQL Errors (continued)
 The mysql_errno() function returns the error code from the last
attempted MySQL function call or 0 if no error occurred
 The mysql_errno() and mysql_error() functions return the
results of the previous mysql*() function
11
12PHP Programming with MySQL, 2nd Edition
Suppressing Errors with the Error
Control Operator
 By default, functions in the mysql package display errors and warnings
as they occur
 Use the error control operator (@) to suppress error messages
 The error control operator can be prepended to any expression although
it is commonly used with expressions
13
Terminating Script Execution
 The die() and exit() functions terminate script execution
 The die() version is usually used when attempting to access a data
source
 Both functions accept a single string argument
 Call the die() and exit() functions as separate statements or by
appending either function to an expression with the Or operator
14
Terminating Script Execution
(continued)
$DBConnect = @mysqli_connect("localhost", "root",
"paris");
if (!$DBConnect)
die("<p>The database server is not available.</p>");
echo "<p>Successfully connected to the database
server.</p>";
$DBSelect = @mysqli_select_db($DBConnect, "flightlog");
if (!$DBSelect)
die("<p>The database is not available.</p>");
echo "<p>Successfully opened the database.</p>";
// additional statements that access the database
mysqli_close($DBConnect);
15
Terminating Script Execution
(continued)
$DBConnect = @mysqli_connect("localhost", "dongosselin",
"rosebud")
Or die("<p>The database server is not
available.</p>");
echo "<p>Successfully connected to the database
server.</p>";
@mysqli_select_db($DBConnect, "flightlog")
Or die("<p>The database is not available.</p>");
echo "<p>Successfully opened the database.</p>";
// additional statements that access the database server
mysqli_close($DBConnect);
16
Reporting MySQL Errors
MySQL error reporting functions
17
Reporting MySQL Errors (continued)
$User = $_GET['username'];
$Password = $_GET['password'];
$DBConnect = @mysqli_connect("localhost", $User, $Password)
Or die("<p>Unable to connect to the database
server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
echo "<p>Successfully connected to the database
server.</p>";
@mysqli_select_db($DBConnect, "flightlog")
Or die("<p>The database is not available.</p>");
echo "<p>Successfully opened the database.</p>";
// additional statements that access the database
mysqli_close($DBConnect);
18
Reporting MySQL Errors (continued)
Figure :- Error number and message generated by
an invalid username and password
19
Reporting MySQL Errors (continued)
$User = $_GET['username'];
$Password = $_GET['password'];
$DBConnect = @mysqli_connect("localhost", $User, $Password)
Or die("<p>Unable to connect to the database
server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
echo "<p>Successfully connected to the database server.</p>";
@mysqli_select_db($DBConnect, "flightplan")
Or die("<p>Unable to select the database.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully opened the database.</p>";
// additional statements that access the database
mysqli_close($DBConnect);
20
Reporting MySQL Errors (continued)
Figure :- Error code and message generated when
attempting to select a database that does not exist
21
Executing SQL Statements
 Use the mysql_query() function to send SQL statements to MySQL
 The syntax for the mysql_query() function is:
mysql_query(query [, connection]);
 The mysql_query() function returns one of three values:
– For SQL statements that do not return results (CREATE DATABASE
and CREATE TABLE statements) it returns a value of TRUE if the
statement executes successfully
22
Executing SQL Statements (continued)
 For SQL statements that return results (SELECT and SHOW
statements) the mysql_query() function returns a result pointer
that represents the query results
 A result pointer is a special type of variable that refers to the
currently selected row in a resultset
 The mysql_query() function returns a value of FALSE for any SQL
statements that fail, regardless of whether they return results
Working with Query Results
23
24
Retrieving Records into an
Indexed Array
 The mysql_fetch_row() function returns the fields in the current
row of a resultset into an indexed array and moves the result pointer to
the next row
echo "<table width='100%‘ border='1'>";
echo "<tr><th>Make</th><th>Model</th>
<th>Price</th><th>Quantity</th></tr>";
$Row = mysql_fetch_row($QueryResult);
do {
echo "<tr><td>{$Row[0]}</td>";
echo "<td>{$Row[1]}</td>";
echo "<td align='right'>{$Row[2]}</td>";
echo "<td align='right'>{$Row[3]}</td></tr>";
$Row = mysql_fetch_row($QueryResult);
} while ($Row);
Retrieving Records into an Indexed
Array
$SQLstring = "SELECT * FROM company_cars";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
echo "<table width='100%' border='1'>n";
echo "<tr><th>License</th><th>Make</th><th>Model</th>
<th>Mileage</th><th>Year</th></tr>n";
while (($Row = mysql_fetch_row($QueryResult)) !== FALSE) {
echo "<tr><td>{$Row[0]}</td>";
echo "<td>{$Row[1]}</td>";
echo "<td>{$Row[2]}</td>";
echo "<td align='right'>{$Row[3]}</td>";
echo "<td>{$Row[4]}</td></tr>n";
}
echo "</table>n";
25
Retrieving Records into an Indexed
Array
26
Figure Output of the company_cars table in a Web Browser
27
Retrieving Records into an Associative
Array
 The mysql_fetch_assoc() function returns the fields in the
current row of a resultset into an associative array and moves the
result pointer to the next row
 The difference between mysql_fetch_assoc() and
mysql_fetch_row() is that instead of returning the fields into
an indexed array, the mysql_fetch_assoc() function returns
the fields into an associate array and uses each field name as the
array key
28PHP Programming with MySQL, 2nd Edition
Accessing Query Result Information
 The mysql_num_rows() function returns the number of rows in a
query result
 The mysql_num_fields() function returns the number of fields in a
query result
 Both functions accept a database connection variable as an argument
29
Accessing Query Result Information
(continued)
$SQLstring = "SELECT * FROM company_cars";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p>Unable to execute the query.</p>"
. "<p>Error code " . mysql_errno($DBConnect)
. ": " . mysql_error($DBConnect) . "</p>";
else
echo "<p>Successfully executed the query.</p>";
$NumRows = mysql_num_rows($QueryResult);
$NumFields = mysql_num_fields($QueryResult);
if ($NumRows != 0 && $NumFields != 0)
echo "<p>Your query returned " .
mysql_num_rows($QueryResult) . " rows and "
. mysql_num_fields($QueryResult) . " fields.</p>";
else
echo "<p>Your query returned no results.</p>";
mysql_close($DBConnect);
30
Accessing Query Result Information
(continued)
Figure :- Output of the number of rows and fields
returned from a query
31
Closing Query Results
 When you are finished working with query results retrieved with the
mysql_query() function, use the mysql_free_result() function to
close the resultset
 To close the resultset, pass to the mysql_free_result() function the
variable containing the result pointer from the mysql_query() function
32
Adding, Deleting, and Updating
Records
 To add records to a table, use the INSERT and VALUES keywords
with the mysqli_query() function
 The values entered in the VALUES list must be in the same order in
which you defined the table fields
 You must specify NULL in any fields for which you do not have a
value
33
Adding, Deleting, and Updating
Records (continued)
 To add multiple records to a database, use the LOAD DATA
statement and the mysqli_query() function with a local text file
containing the records you want to add
 To update records in a table, use the UPDATE, SET, and WHERE
keywords with the mysqli_query() function
34
Adding, Deleting, and Updating
Records (continued)
 The UPDATE keyword specifies the name of the table to update
 The SET keyword specifies the value to assign to the fields in the
records that match the condition in the WHERE keyword
 To delete records in a table, use the DELETE and WHERE
keywords with the mysqli_query() function
 The WHERE keyword determines which records to delete in the
table
35
Using the mysql_affected_rows()
Function
 With queries that return results (SELECT queries), use the
mysql_num_rows() function to find the number of records
returned from the query
 With queries that modify tables but do not return results (INSERT,
UPDATE, and DELETE queries), use the
mysql_affected_rows() function to determine the number of
affected rows
36
Using the mysql_affected_rows() Function
(continued)
$SQLstring = "UPDATE company_cars SET mileage=50112.3
WHERE license='AK-1234'";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p>Unable to execute the query.</p>"
. "<p>Error code " . mysql_errno($DBConnect)
. ": " . mysql_error($DBConnect) . "</p>";
else
echo "<p>Successfully updated "
. mysql_affected_rows($DBConnect) . "
record(s).</p>";
37
Using the mysql_affected_rows() Function
(continued)
Figure :- Output of mysql_affected_rows() function
for an UPDATE query
38
Using the mysql_info() Function
 For queries that add or update records, or alter
a table’s structure, use the mysql_info() function to return
information about the query
 The mysql_info() function returns the number of operations for
various types of actions, depending on the type of query
 The mysql_info() function returns information about the last
query that was executed on the database connection
39
Using the mysql_info() Function
(continued)
 The mysql_info() function returns information about queries that
match one of the following formats:
– INSERT INTO...SELECT...
– INSERT INTO...VALUES (...),(...),(...)
– LOAD DATA INFILE ...
– ALTER TABLE ...
– UPDATE
 For any queries that do not match one of these formats, the
mysql_info() function returns an empty string
40
Using the mysql_info() Function
(continued)
$SQLstring = "INSERT INTO company_cars " .
" (license, model_year, make, model, mileage) " .
" VALUES " .
" ('CPQ-894', 2011, 'Honda', 'Insight', 49.2), " .
" ('CPQ-895', 2011, 'Honda', 'Insight', 17.9), " .
" ('CPQ-896', 2011, 'Honda', 'Insight', 22.6)";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p>Unable to execute the query.</p>"
. "<p>Error code " . mysql_errno($DBConnect)
. ": " . mysql_error($DBConnect) . "</p>";
else {
echo "<p>Successfully added the record.</p>";
echo "<p>" . mysql_info($DBConnect) . "</p>";
}
41
Using the mysql_info() Function
(continued)
Figure :- Output of mysql_info() function for an
INSERT query that adds multiple records
42
Using the mysql_info() Function
(continued)
 The mysql_info() function also returns information for LOAD DATA
queries
$SQLstring = "LOAD DATA INFILE 'company_cars.txt'
INTO TABLE company_cars;";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if ($QueryResult === FALSE)
echo "<p>Unable to execute the query.</p>"
. "<p>Error code " . mysql_errno($DBConnect)
. ": " . mysql_error($DBConnect) . "</p>";
else {
echo "<p>Successfully added the record.</p>";
echo "<p>" . mysql_info($DBConnect) . "</p>";
}
43
Using the mysql_info() Function
(continued)
Figure :- Output of mysql_info() function for a LOAD DATA
query
44
Summary
 The mysql_connect() function opens a
connection to a MySQL database server
 The mysql_close() function closes a
database connection
 The mysql_errno() function returns the
error code from the last attempted MySQL
function call or zero if no error occurred
45
Summary (continued)
 The mysql_error() function returns the error message from
the last attempted MySQL function call or an empty string if no
error occurred
 The error control operator (@) suppresses error messages
 You use the mysql_create_db() function to create a new
database
 The mysql_select_db() function selects a database
46
Summary (continued)
 You use the mysql_drop_db() function to delete a
database
 The mysql_query() function sends SQL statements
to MySQL
 A result pointer is a special type of variable that refers
to the currently selected row in a resultset
 You use the CREATE TABLE statement with the
mysql_query() function to create a table
47
Summary (continued)
 The PRIMARY KEY clause indicates a field or fields
that will be used as a referential index for the table
 The AUTO_INCREMENT clause creates a field that is
automatically updated with the next sequential value
for that column
 The NOT NULL clause creates a field that must
contain data
 You use the DROP TABLE statement with the
mysql_query() function to delete a table
48
Summary (continued)
 You use the LOAD DATA statement and the
mysql_query() function with a local text file to add
multiple records to a database
 You use the UPDATE statement with the
mysql_query() function to update records in a table
 You use the DELETE statement with the
mysql_query() function to delete records from a
table
49
Summary (continued)
 The mysql_info() function returns the number of
operations for various types of actions, depending on the
type of query.
 The mysql_fetch_row() function returns the fields in the
current row of a resultset into an indexed array and moves
the result pointer to the next row.
50
Summary (continued)
 The mysql_fetch_assoc() function
returns the fields in the current row of a
resultset into an associative array and moves
the result pointer to the next row
 The mysql_free_result() function
closes a resultset
51
Summary (continued)
 The mysql_num_rows() function returns
the number of rows in a query result, and the
mysql_num_fields() function returns the
number of fields in a query result
 With queries that return results, such as
SELECT queries, you can use the
mysql_num_rows() function to find the
number of records returned from the query
VIJAY KUMAR SHARMA
?
THE END
Contact No. 8385056379
http://www.kumarvijaybaswa.blogspot.in

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
php
phpphp
php
 
Php forms
Php formsPhp forms
Php forms
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Jquery
JqueryJquery
Jquery
 
Php
PhpPhp
Php
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
jQuery
jQueryjQuery
jQuery
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 

Ähnlich wie Php with MYSQL Database

Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sqlsaritasingh19866
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part IIFirdaus Adib
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08Terry Yoast
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erickokelloerick
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sqlsalissal
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxmoirarandell
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Developmentw3ondemand
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
Php mysql connectivity
Php mysql connectivityPhp mysql connectivity
Php mysql connectivityabhikwb
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDatabase Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesDave Stokes
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesRasan Samarasinghe
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQLArti Parab Academics
 

Ähnlich wie Php with MYSQL Database (20)

Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sql
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erick
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
 
Php verses my sql
Php verses my sqlPhp verses my sql
Php verses my sql
 
Php mysql connectivity
Php mysql connectivityPhp mysql connectivity
Php mysql connectivity
 
UNIT V (5).pptx
UNIT V (5).pptxUNIT V (5).pptx
UNIT V (5).pptx
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDatabase Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
 
Php summary
Php summaryPhp summary
Php summary
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
Php mysq
Php mysqPhp mysq
Php mysq
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
 

Mehr von Computer Hardware & Trouble shooting (7)

Vlsm
VlsmVlsm
Vlsm
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Storing data : Disk Organization and I/O
Storing data : Disk Organization and I/OStoring data : Disk Organization and I/O
Storing data : Disk Organization and I/O
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Mcse question
Mcse questionMcse question
Mcse question
 
Css notes
Css notesCss notes
Css notes
 
File organization
File organizationFile organization
File organization
 

Kürzlich hochgeladen

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 

Kürzlich hochgeladen (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 

Php with MYSQL Database

  • 1. MySQL Databases with PHP PHP Programming with MySQL
  • 2. 2 Objectives  Connect to MySQL from PHP  Work with MySQL databases using PHP  Create, modify, and delete MySQL tables with PHP  Use PHP to manipulate MySQL records  Use PHP to retrieve database records
  • 3. 3 Connecting to MySQL with PHP  PHP has the ability to access and manipulate any database that is ODBC compliant  PHP includes functionality that allows you to work directly with different types of databases, without going through ODBC  PHP supports SQLite, database abstraction layer functions, and PEAR DB
  • 4. 4 Opening and Closing a MySQL Connection  Open a connection to a MySQL database server with the mysql_connect() function  The mysql_connect() function returns a positive integer if it connects to the database successfully or FALSE if it does not  Assign the return value from the mysql_connect() function to a variable that you can use to access the database in your script
  • 5. 5 Opening and Closing a MySQL Connection (continued)  The syntax for the mysql_connect() function is: $connection = mysql_connect("host" [, "user", "password"]);  The host argument specifies the host name where your MySQL database server is installed  The user and password arguments specify a MySQL account name and password
  • 6. 6 Opening and Closing a MySQL Connection (continued)  The database connection is assigned to the $DBConnect variable $DBConnect = mysql_connect("localhost", "dongosselin ", "rosebud");  Close a database connection using the mysql_close() function mysql_close($DBConnect);
  • 7. 7 Opening and Closing a MySQL Connection (continued)
  • 8. 8 Opening and Closing a MySQL Connection (continued) MySQLInfo.php in a Web browser
  • 9. 9 Selecting a Database  The syntax for the mysql_select_db() function is: mysql_select_db(database [, connection]);  The function returns a value of TRUE if it successfully selects a database or FALSE if it does not  For security purposes, you may choose to use an include file to connect to the MySQL server and select a database
  • 10. 10 Reporting MySQL Errors  Reasons for not connecting to a database server include:  The database server is not running  Insufficient privileges to access the data source  Invalid username and/or password
  • 11. Reporting MySQL Errors (continued)  The mysql_errno() function returns the error code from the last attempted MySQL function call or 0 if no error occurred  The mysql_errno() and mysql_error() functions return the results of the previous mysql*() function 11
  • 12. 12PHP Programming with MySQL, 2nd Edition Suppressing Errors with the Error Control Operator  By default, functions in the mysql package display errors and warnings as they occur  Use the error control operator (@) to suppress error messages  The error control operator can be prepended to any expression although it is commonly used with expressions
  • 13. 13 Terminating Script Execution  The die() and exit() functions terminate script execution  The die() version is usually used when attempting to access a data source  Both functions accept a single string argument  Call the die() and exit() functions as separate statements or by appending either function to an expression with the Or operator
  • 14. 14 Terminating Script Execution (continued) $DBConnect = @mysqli_connect("localhost", "root", "paris"); if (!$DBConnect) die("<p>The database server is not available.</p>"); echo "<p>Successfully connected to the database server.</p>"; $DBSelect = @mysqli_select_db($DBConnect, "flightlog"); if (!$DBSelect) die("<p>The database is not available.</p>"); echo "<p>Successfully opened the database.</p>"; // additional statements that access the database mysqli_close($DBConnect);
  • 15. 15 Terminating Script Execution (continued) $DBConnect = @mysqli_connect("localhost", "dongosselin", "rosebud") Or die("<p>The database server is not available.</p>"); echo "<p>Successfully connected to the database server.</p>"; @mysqli_select_db($DBConnect, "flightlog") Or die("<p>The database is not available.</p>"); echo "<p>Successfully opened the database.</p>"; // additional statements that access the database server mysqli_close($DBConnect);
  • 16. 16 Reporting MySQL Errors MySQL error reporting functions
  • 17. 17 Reporting MySQL Errors (continued) $User = $_GET['username']; $Password = $_GET['password']; $DBConnect = @mysqli_connect("localhost", $User, $Password) Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; echo "<p>Successfully connected to the database server.</p>"; @mysqli_select_db($DBConnect, "flightlog") Or die("<p>The database is not available.</p>"); echo "<p>Successfully opened the database.</p>"; // additional statements that access the database mysqli_close($DBConnect);
  • 18. 18 Reporting MySQL Errors (continued) Figure :- Error number and message generated by an invalid username and password
  • 19. 19 Reporting MySQL Errors (continued) $User = $_GET['username']; $Password = $_GET['password']; $DBConnect = @mysqli_connect("localhost", $User, $Password) Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; echo "<p>Successfully connected to the database server.</p>"; @mysqli_select_db($DBConnect, "flightplan") Or die("<p>Unable to select the database.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; echo "<p>Successfully opened the database.</p>"; // additional statements that access the database mysqli_close($DBConnect);
  • 20. 20 Reporting MySQL Errors (continued) Figure :- Error code and message generated when attempting to select a database that does not exist
  • 21. 21 Executing SQL Statements  Use the mysql_query() function to send SQL statements to MySQL  The syntax for the mysql_query() function is: mysql_query(query [, connection]);  The mysql_query() function returns one of three values: – For SQL statements that do not return results (CREATE DATABASE and CREATE TABLE statements) it returns a value of TRUE if the statement executes successfully
  • 22. 22 Executing SQL Statements (continued)  For SQL statements that return results (SELECT and SHOW statements) the mysql_query() function returns a result pointer that represents the query results  A result pointer is a special type of variable that refers to the currently selected row in a resultset  The mysql_query() function returns a value of FALSE for any SQL statements that fail, regardless of whether they return results
  • 23. Working with Query Results 23
  • 24. 24 Retrieving Records into an Indexed Array  The mysql_fetch_row() function returns the fields in the current row of a resultset into an indexed array and moves the result pointer to the next row echo "<table width='100%‘ border='1'>"; echo "<tr><th>Make</th><th>Model</th> <th>Price</th><th>Quantity</th></tr>"; $Row = mysql_fetch_row($QueryResult); do { echo "<tr><td>{$Row[0]}</td>"; echo "<td>{$Row[1]}</td>"; echo "<td align='right'>{$Row[2]}</td>"; echo "<td align='right'>{$Row[3]}</td></tr>"; $Row = mysql_fetch_row($QueryResult); } while ($Row);
  • 25. Retrieving Records into an Indexed Array $SQLstring = "SELECT * FROM company_cars"; $QueryResult = @mysql_query($SQLstring, $DBConnect); echo "<table width='100%' border='1'>n"; echo "<tr><th>License</th><th>Make</th><th>Model</th> <th>Mileage</th><th>Year</th></tr>n"; while (($Row = mysql_fetch_row($QueryResult)) !== FALSE) { echo "<tr><td>{$Row[0]}</td>"; echo "<td>{$Row[1]}</td>"; echo "<td>{$Row[2]}</td>"; echo "<td align='right'>{$Row[3]}</td>"; echo "<td>{$Row[4]}</td></tr>n"; } echo "</table>n"; 25
  • 26. Retrieving Records into an Indexed Array 26 Figure Output of the company_cars table in a Web Browser
  • 27. 27 Retrieving Records into an Associative Array  The mysql_fetch_assoc() function returns the fields in the current row of a resultset into an associative array and moves the result pointer to the next row  The difference between mysql_fetch_assoc() and mysql_fetch_row() is that instead of returning the fields into an indexed array, the mysql_fetch_assoc() function returns the fields into an associate array and uses each field name as the array key
  • 28. 28PHP Programming with MySQL, 2nd Edition Accessing Query Result Information  The mysql_num_rows() function returns the number of rows in a query result  The mysql_num_fields() function returns the number of fields in a query result  Both functions accept a database connection variable as an argument
  • 29. 29 Accessing Query Result Information (continued) $SQLstring = "SELECT * FROM company_cars"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else echo "<p>Successfully executed the query.</p>"; $NumRows = mysql_num_rows($QueryResult); $NumFields = mysql_num_fields($QueryResult); if ($NumRows != 0 && $NumFields != 0) echo "<p>Your query returned " . mysql_num_rows($QueryResult) . " rows and " . mysql_num_fields($QueryResult) . " fields.</p>"; else echo "<p>Your query returned no results.</p>"; mysql_close($DBConnect);
  • 30. 30 Accessing Query Result Information (continued) Figure :- Output of the number of rows and fields returned from a query
  • 31. 31 Closing Query Results  When you are finished working with query results retrieved with the mysql_query() function, use the mysql_free_result() function to close the resultset  To close the resultset, pass to the mysql_free_result() function the variable containing the result pointer from the mysql_query() function
  • 32. 32 Adding, Deleting, and Updating Records  To add records to a table, use the INSERT and VALUES keywords with the mysqli_query() function  The values entered in the VALUES list must be in the same order in which you defined the table fields  You must specify NULL in any fields for which you do not have a value
  • 33. 33 Adding, Deleting, and Updating Records (continued)  To add multiple records to a database, use the LOAD DATA statement and the mysqli_query() function with a local text file containing the records you want to add  To update records in a table, use the UPDATE, SET, and WHERE keywords with the mysqli_query() function
  • 34. 34 Adding, Deleting, and Updating Records (continued)  The UPDATE keyword specifies the name of the table to update  The SET keyword specifies the value to assign to the fields in the records that match the condition in the WHERE keyword  To delete records in a table, use the DELETE and WHERE keywords with the mysqli_query() function  The WHERE keyword determines which records to delete in the table
  • 35. 35 Using the mysql_affected_rows() Function  With queries that return results (SELECT queries), use the mysql_num_rows() function to find the number of records returned from the query  With queries that modify tables but do not return results (INSERT, UPDATE, and DELETE queries), use the mysql_affected_rows() function to determine the number of affected rows
  • 36. 36 Using the mysql_affected_rows() Function (continued) $SQLstring = "UPDATE company_cars SET mileage=50112.3 WHERE license='AK-1234'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else echo "<p>Successfully updated " . mysql_affected_rows($DBConnect) . " record(s).</p>";
  • 37. 37 Using the mysql_affected_rows() Function (continued) Figure :- Output of mysql_affected_rows() function for an UPDATE query
  • 38. 38 Using the mysql_info() Function  For queries that add or update records, or alter a table’s structure, use the mysql_info() function to return information about the query  The mysql_info() function returns the number of operations for various types of actions, depending on the type of query  The mysql_info() function returns information about the last query that was executed on the database connection
  • 39. 39 Using the mysql_info() Function (continued)  The mysql_info() function returns information about queries that match one of the following formats: – INSERT INTO...SELECT... – INSERT INTO...VALUES (...),(...),(...) – LOAD DATA INFILE ... – ALTER TABLE ... – UPDATE  For any queries that do not match one of these formats, the mysql_info() function returns an empty string
  • 40. 40 Using the mysql_info() Function (continued) $SQLstring = "INSERT INTO company_cars " . " (license, model_year, make, model, mileage) " . " VALUES " . " ('CPQ-894', 2011, 'Honda', 'Insight', 49.2), " . " ('CPQ-895', 2011, 'Honda', 'Insight', 17.9), " . " ('CPQ-896', 2011, 'Honda', 'Insight', 22.6)"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else { echo "<p>Successfully added the record.</p>"; echo "<p>" . mysql_info($DBConnect) . "</p>"; }
  • 41. 41 Using the mysql_info() Function (continued) Figure :- Output of mysql_info() function for an INSERT query that adds multiple records
  • 42. 42 Using the mysql_info() Function (continued)  The mysql_info() function also returns information for LOAD DATA queries $SQLstring = "LOAD DATA INFILE 'company_cars.txt' INTO TABLE company_cars;"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else { echo "<p>Successfully added the record.</p>"; echo "<p>" . mysql_info($DBConnect) . "</p>"; }
  • 43. 43 Using the mysql_info() Function (continued) Figure :- Output of mysql_info() function for a LOAD DATA query
  • 44. 44 Summary  The mysql_connect() function opens a connection to a MySQL database server  The mysql_close() function closes a database connection  The mysql_errno() function returns the error code from the last attempted MySQL function call or zero if no error occurred
  • 45. 45 Summary (continued)  The mysql_error() function returns the error message from the last attempted MySQL function call or an empty string if no error occurred  The error control operator (@) suppresses error messages  You use the mysql_create_db() function to create a new database  The mysql_select_db() function selects a database
  • 46. 46 Summary (continued)  You use the mysql_drop_db() function to delete a database  The mysql_query() function sends SQL statements to MySQL  A result pointer is a special type of variable that refers to the currently selected row in a resultset  You use the CREATE TABLE statement with the mysql_query() function to create a table
  • 47. 47 Summary (continued)  The PRIMARY KEY clause indicates a field or fields that will be used as a referential index for the table  The AUTO_INCREMENT clause creates a field that is automatically updated with the next sequential value for that column  The NOT NULL clause creates a field that must contain data  You use the DROP TABLE statement with the mysql_query() function to delete a table
  • 48. 48 Summary (continued)  You use the LOAD DATA statement and the mysql_query() function with a local text file to add multiple records to a database  You use the UPDATE statement with the mysql_query() function to update records in a table  You use the DELETE statement with the mysql_query() function to delete records from a table
  • 49. 49 Summary (continued)  The mysql_info() function returns the number of operations for various types of actions, depending on the type of query.  The mysql_fetch_row() function returns the fields in the current row of a resultset into an indexed array and moves the result pointer to the next row.
  • 50. 50 Summary (continued)  The mysql_fetch_assoc() function returns the fields in the current row of a resultset into an associative array and moves the result pointer to the next row  The mysql_free_result() function closes a resultset
  • 51. 51 Summary (continued)  The mysql_num_rows() function returns the number of rows in a query result, and the mysql_num_fields() function returns the number of fields in a query result  With queries that return results, such as SELECT queries, you can use the mysql_num_rows() function to find the number of records returned from the query
  • 52. VIJAY KUMAR SHARMA ? THE END Contact No. 8385056379 http://www.kumarvijaybaswa.blogspot.in