Question

I'm using SQLite 3 with PHP.

The SQLite table consists of 2 INTEGER and one FLOAT column. When saving data into this table using PHP floats are not saved correctly (default value is stored instead). The two integer columns are saved. Any ideas what could be wrong? Thank you.

Simplified code that actually works correctly:

$conn = new SQLite3('dbFileName');
$conn->query("CREATE TABLE data (
       id INTEGER NOT NULL DEFAULT 0 ,
       ts INTEGER NOT NULL DEFAULT 0 ,
       value FLOAT NOT NULL DEFAULT 0
    );"
);
$conn->query("REPLACE INTO data(id,ts,value) VALUES ('1','1234567890','12.1')");

-> 1|1234567890|0

No correct solution

OTHER TIPS

This is just a suggestion, seeing as I have never used SQLite, but are you sure the numbers should be quoted? That seems somewhat odd to me.

Try:

$conn->query("REPLACE INTO data(id,ts,value) VALUES (1, 1234567890, 12.1)");

Sqlite data types are typeless, so your queries have to work:

all the following queries works for me

REPLACE INTO data(id,ts,value) VALUES ('1','1234567890','12.1');
REPLACE INTO data(id,ts,value) VALUES ('1','1234567890','12,123')
REPLACE INTO data(id,ts,value) VALUES ('1','1234567890','abc');

Check your PHP variable, you might have a bug and you pass a null variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top