I have
$result = pg_query($dbconn, 'SELECT * FROM domain');
$d = pg_fetch_all($result);
var_dump($d);
And the result is
array(2) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["domainname"]=>
string(15) "stackoverflow.com"
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["domainname"]=>
string(13) "example.com"
}
}
Here the problem is that the id
s are shown as string even though they are integers. How can I get them as integers automatically?
It's up to you to manually convert the string into an appropriate numerical type, and to verify that the number represented by the string fits in that numerical type.
Even though many times the integer used internally in the database can be the same bytesize as the integer type used by php, there are too many special cases (like 64-bit database numbers coming back to a 32-bit PHP binary, etc.) for any particular automatic conversion policy to be acceptable.
More generally, PostgreSQL has numeric
and decimal
types that have "up to 131072 digits before the decimal point" and "up to 16383 digits after the decimal point" (see Table 8-2 [in the PostgreSQL docs]).(https://www.postgresql.org/docs/9.1/static/datatype-numeric.html