$pdo = new PDO('mysql:dbname=database;host=localhost;charset=UTF-8', 'username', 'password',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
...
$total = $pdo->query('SELECT COUNT(*) FROM database')->fetchColumn();
Monday, January 21, 2013
How to get row count from MySQL with PHP/PDO
PDOStatement::rowCount() does not work well with MySQL, so here is the workaround code:
Subscribe to:
Post Comments (Atom)
prepare($sql);
ReplyDelete$stmt->execute();
$stmt->bind_result($P_id, $product_name, $product_price);
while($stmt->fetch()){
$temp = [
'P_id'=>$P_id,
'product_name'=>$product_name,
'product_price'=>$product_price
];
array_push($android, $temp);
}
echo json_encode($android);
}
else{
die("Connection failed: " . $conn->connect_error);
}
?>
how to count row from table and print using jeson
prepare($sql);
ReplyDelete$stmt->execute();
$stmt->bind_result($P_id, $product_name, $product_price);
while($stmt->fetch()){
$temp = [
'P_id'=>$P_id,
'product_name'=>$product_name,
'product_price'=>$product_price
];
array_push($android, $temp);
}
echo json_encode($android);
}
else{
die("Connection failed: " . $conn->connect_error);
}
?>
how to count row from and print it