- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we write PHP script to count the affected rows by MySQL query?
PHP uses mysql_affected_rows( ) function to find out how many rows a query changed. To illustrate it we are having the following example −
Example
<html> <head> <title>Rows affected by query</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br />'; mysql_select_db( 'TUTORIALS' ); $result_id = mysql_query ($query, $conn_id); # report 0 rows if the query failed $count = ($result_id ? mysql_affected_rows ($conn_id) : 0); print ("$count rows were affected
"); ?> </body> </html>
- Related Articles
- How can we get the total number of rows affected by MySQL query?
- Which PHP function is used to give the number of rows affected by MySQL query?
- How can we write PHP script to get the list of MySQL database?
- How can we delete a MySQL database by using PHP script?
- How can we select a MySQL database by using PHP script?
- How can we create a MySQL table by using PHP script?
- How can we write PHP script to release cursor memory associated with MySQL result?
- How can we delete an existing MySQL table by using PHP script?
- How can we create a MySQL temporary table by using PHP script?
- How can we insert data into an existing MySQL table by using PHP script?
- Create a MySQL stored procedure that counts the number of rows gets affected by MySQL query?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- How can we create a new database by using PHP script?
- How to write PHP script by using MySQL JOINS inside it to join two MySQL tables?
- How to write PHP script to update an existing MySQL table?

Advertisements