Is it possible when querying from DB to number?

PDO, PHP, MySQL. Any request for example:
SELECT COUNT(*) FROM `table` WHERE id=1

Returns for example:
array(1) {
[0]=>
 array(1) {
["COUNT(*)"]=>
 string(1) "1"
}
}

Please note that 1 is a string and not a number. We have to keep in mind and more or to make an inaccurate comparison == what are fraught or ==='1' or insert a conversion to number that is not humane. It is possible to do something and what do you do in such cases?
July 2nd 19 at 14:13
3 answers
July 2nd 19 at 14:15
Solution
you: just need to use Nativ driver + prepared statements.
I have a complete query like this, but something doesn't help
$db = $pdo->prepare(' SELECT COUNT(*) FROM `table` WHERE id=:id ');
$db->bindParam(':id', $Id, PDO::PARAM_INT);
$db->execute();
$result = $db->fetchAll();
- Tyreek.Stoke commented on July 2nd 19 at 14:18
Need to fetchAll() is probably something need to register - Tyreek.Stoke commented on July 2nd 19 at 14:21
: $pdo = new PDO('mysql:host=localhost;dbname=table', $user, $pass, [PDO::ATTR_EMULATE_PREPARES => false]); - kavon.Murphy commented on July 2nd 19 at 14:24
July 2nd 19 at 14:17
Solution
I don't know about numbers, but number can. Use prepared queries with bind the result to variables using bindColumn().
Nonsense - Tyreek.Stoke commented on July 2nd 19 at 14:20
: Justify. - Tyreek.Stoke commented on July 2nd 19 at 14:23
I'm sorry, I was wrong. Considering that spits bindParam for PDO::PARAM_INT, I did not expect that it works in the opposite direction. - kavon.Murphy commented on July 2nd 19 at 14:26
I would like some details to know exactly how the application bindColumn will translate the string representation of the int in the documentation this is not mentioned php.net/pdostatement.bindcolumn - Mellie.Cronin commented on July 2nd 19 at 14:29
:
$req = $pdo->prepare("SELECT `id` FROM `requests` LIMIT 1");
$req->execute();
list($id) = $req->fetch(PDO::FETCH_NUM);
var_dump($id);

string(3) "886"

$req = $pdo->prepare("SELECT `id` FROM `requests` LIMIT 1");
$req->bindColumn(1, $id, PDO::PARAM_INT);
$req->execute();
$req->fetch(PDO::FETCH_BOUND);
var_dump($id);

int(886) - Kenyatta commented on July 2nd 19 at 14:32
July 2nd 19 at 14:19
Solution
Translate into plain language the response :

To get this functionality, it is necessary to respect two conditions:

the pdo_mysql module must be assembled on the basis of mysqlnd. verified via phpinfo()
for the query using native prepared statements, which is achieved by setting PDO::ATTR_EMULATE_PREPARES to false

Find more questions by tags PHP PDOPHP