php - PDO PDOStatement always outputs 1 in the end -
i new pdo , have been checking around answers not find one. reason pdostatement object outputs 1 in end.
for example when this
$username = 'alexander'; $sql = " select username, email user username = :username; "; $stmt = $dbh->prepare($sql); $stmt->bindparam(':username', $username); $stmt->execute(); $result = $stmt->fetch(pdo::fetch_assoc); echo '<pre>', print_r($result), '</pre>';
it outputs
array ( [username] => alexander [email] => alex@live.com ) 1
notice 1 in end. , example when use rowcount() check affected rows after update statement this
$username = 'martin'; $sql = " update user set username = :username id = 1; "; $stmt = $dbh->prepare($sql); $stmt->bindparam(':username', $username); $stmt->execute(); $affected = $stmt->rowcount(); echo '<pre>', print_r($affected), '</pre>';
now outputs not 1 11 because of 1 in end there no matter what. , if query again not 0 01. normal? how can distinguish between 0, 1 , 01 again because of 1 there every time. don't understand behavior, point of 1 in end?
you'll need use print_r($var, 1)
in order remove , return string rather true
.
in manual:
mixed print_r ( mixed $expression [, bool $return = false ] )
when return parameter true, function return string. otherwise, return value true.
so add flag:
echo '<pre>', print_r($affected, 1), '</pre>'; // ^ or `true`
Comments
Post a Comment