Latest web development tutorials

PDOStatement :: closeCursor

PHP PDO Reference Manual PHP PDO Reference Manual

PDOStatement :: closeCursor - close the cursor, so that the statement can be executed again. (PHP 5> = 5.1.0, PECL pdo> = 0.9.0)


Explanation

grammar

bool PDOStatement::closeCursor ( void )

PDOStatement :: closeCursor () releases the connection to the database service, in order to send other SQL statement, but to make a statement in a state that can be executed again.

When executing a PDOStatement object still has not taken a row, this method is very useful for drivers who do not support the re-implementation of a PDOStatement object database. If the database driver so limited, the disorder may appear wrong question.

PDOStatement :: closeCursor () method specific to either an optional drive (most efficient) to achieve, either in the absence of the drive to achieve a particular function as a general PDO spare. General spare semantically identical with the following PHP code:

<?php
do {
    while ($stmt->fetch())
        ;
    if (!$stmt->nextRowset())
        break;
} while (true);
?>

return value

Successful return TRUE, or on failure returns FALSE.


Examples

A PDOStatement :: closeCursor () example

In the following example, $ stmt PDOStatement object returns multiple rows but the application takes only the first line, so PDOStatement object is in a state not to take the line. To ensure that applications can run properly on all database-driven, executing $ otherStmt before PDOStatement objects, $ stmt called once PDOStatement :: closeCursor ().

<?php
/* 创建一个 PDOStatement 对象 */
$stmt = $dbh->prepare('SELECT foo FROM bar');

/* 创建第二个 PDOStatement 对象 */
$otherStmt = $dbh->prepare('SELECT foobaz FROM foobar');

/* 执行第一条语句 */
$stmt->execute();

/*  从结果集中只取出第一行 */
$stmt->fetch();

/* The following call to closeCursor() may be required by some drivers */
$stmt->closeCursor();

/*  现在可以执行第二条语句了 */
$otherStmt->execute();
?>

PHP PDO Reference Manual PHP PDO Reference Manual