Welcome Guest, Not a member yet? Register   Sign In
Get data in type from DB
#1

+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| term | varchar(255) | NO | | NULL | |
| level | int(11) | NO | | NULL | |
+-------+--------------+------+-----+---------+----------------+


Result

array(4) {
[0]=>
array(3) {
["id"]=>
string(1) "1"
["term"]=>
string(11) "Mesoamerica"
["level"]=>
string(1) "1"
}
[1]=>
array(3) {
["id"]=>
string(1) "2"
["term"]=>
string(6) "Mexico"
["level"]=>
string(1) "1"
}
[2]=>
array(3) {
["id"]=>
string(1) "3"
["term"]=>
string(10) "indigenous"
["level"]=>
string(1) "2"
}
[3]=>
array(3) {
["id"]=>
string(1) "4"
["term"]=>
string(5) "ruins"
["level"]=>
string(1) "2"
}
}

but i need ID if integer instead
Reply
#2

MySQL will return most things as a string since each programming language has a different set of primitive types.

If you're using Entities, you can cast the column to an int as described in the user guide.

If you're not using entities, you'll have to do that yourself. You can always check with is_numeric, but PHP will automatically typecast from string to int if needed.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB