문제

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

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top