Php:pdostatement::rowcount () method parameter Description ____php

Source: Internet
Author: User
Tags rowcount
Pdostatement::rowcount

(PHP 5 >= 5.1.0, PECL PDO >= 0.1.0)

pdostatement::rowcount-Returns a description of the number of rows affected by the previous SQL statement int pdostatement::rowcount (void)

pdostatement::rowcount () returns the number of rows that were affected by the previous delete, INSERT, or UPDATE statement by the corresponding Pdostatement object.

If the previous SQL statement executed by a related pdostatement is a SELECT statement, some data may return the number of rows returned by this statement. However, this approach is not guaranteed to be valid for all data and should not be dependent on this approach for portable applications. return value

Returns the number of rows. Example

Example #1 Returns the number of rows deleted

pdostatement::rowcount () returns the number of rows affected by the DELETE, INSERT, or UPDATE statement.

<?php
/* Remove all rows from the FRUIT datasheet/* *
$del = $dbh->prepare (' Delete from FRUIT ');
$del->execute ();

/* Returns the number of rows to be deleted
/print ("Return count of rows that were Deleted:n");
$count = $del->rowcount ();
Print ("Deleted $count ROWS.N");
? >

The above routines will output:

Return number of rows that were deleted:
deleted 9 rows.

Example #2 calculates the number of rows returned by a SELECT statement

For most databases,Pdostatement::rowcount () cannot return the number of rows affected by a single SELECT statement. Instead, use Pdo::query () to emit a select count (*) statement that has the same conditional expression as the SELECT statement in the original plan, and then use Pdostatement::fetchcolumn () to get the number of rows returned. This allows the application to execute correctly.

<?php $sql  =  "select count (*)  FROM fruit WHERE calories > 
100 "; if  ($res  =  $conn->query ($sql))  {    /*  Check Compliance  SELECT  The number of lines in the statement  */  if  ($res->fetchcolumn ()  > 0)  {         /*  issue a real  SELECT  statement and manipulate the results returned  */           $sql  =  "select name from fruit where calories 
> 100 ";        foreach  ($conn->query ($sql)  as  $row)  {            print  "name: "  .   $row ['
NAME '] .  ' n ';          }     }     /*   No matching rows  --  perform other  */  else {&NBSP;&NBSP;&NBSP;&Nbsp;  print  "No rows matched the query."
&NBSP;&NBSP;&NBSP;&NBSP} $res  = null;
 $conn  = null;?>

The above routines will output:

Apple
banana
orange
Pear

See

Pdostatement::columncount ()-Returns the number of columns in the result set Pdostatement::fetchcolumn ()-Returns a separate column from the next row in the result set. Pdo::query ()-Executes a SQL statement, returning a result set as a Pdostatement object

Php:pdostatement::nextrowset () method parameter description
Pdostatement::nextrowset (php5=5.1.0,peclpdo=0.2.0) Pdostatement:: Nextrowset in a multiline set statement handle to the next rowset description Boolpdostatement::nextrowset (void) Some database service support

Php:pdostatement::getcolumnmeta () method parameter description
Pdostatement::getcolumnmeta (php5=5.1.0,peclpdo=0.2.0) Pdostatement:: Getcolumnmeta returns a column in the result set of metadata description Arraypdostatement::getcolumnmeta (int$column) Warning this function is experimental.

Php:pdostatement::getattribute () method parameter description
Pdostatement::getattribute (php5=5.1.0,peclpdo=0.2.0) Pdostatement::getattribute Retrieves a statement property description Mixedpdostatement:: GetAttribute (Int$attribute) Gets an attribute of the statement. Currently, do not save

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.