I'm trying to connect from PHP to a ms access database and, with help from here, so far so good!
But all data retrieved is "String" type, even date/time and numeric fields are converted to string in php. And some numeric values only show a string with "E2".
Here is my code:
$dbName = "database.accdb"; $conn2 = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$dbName;Uid=Admin"); $conn2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn2->prepare("SELECT * FROM table"); $stmt->execute(); $result= $stmt->fetchAll(); There are numeric fields, string fields, and date/time fields in that table, but the array $result has data type "String" in all elements. Used gettype() to check.
The problem is that numeric values get converted sometimes to "0.0353125" (for example) or only "E-3" or "E-2"
How can I get the correct value in my $result array? What am I doing wrong?
Thanks a lot
is_float(mixed $var)to check if you variable is a float.is_float()actually try to transform everything (including a string) into a float number. If it succeed, it returns true. So if you dois_float('test');it returns false, but if you dois_float('1.896e-5');it returns true because this string can be "parsed" into a float.