I've got postgres table with an auto-incremental column, and attempting to insert data from PHP with pg_insert returns a string key error. How would I go about modifying this for the different datatypes?
$username = $_SESSION['username'];
$data_timestamp = array(round(microtime(true) * 1000));
$data_username = array($username);
array_splice($data_to_store, 0, 0, $data_timestamp);
array_splice($data_to_store, 3, 0, $data_username);
var_dump($data_to_store);
$last_id = pg_insert($getPgInstance, 'app.features', $data_to_store);
Currently returns the following error:
Warning: pg_insert(): Accepts only string key for values in /var/www/html/admin/add_table.php on line 24
insert failed: Array ( [0] => 1609941177697 [1] => username [2] => real_name [3] => staff_account [4] => dummydatareason [5] => accounttype )
A var_dump returns:
array(6) { [0]=> float(1609941177697) ["username"]=> string(4) "user" ["real_name"]=> string(4) "disp" [1]=> string(15) "dummydatareasontext" ["reason"]=> string(14) "sdfdsfpassssss" ["Type"]=> string(13) "accounttype" }
My Postgres table is made up of:
id integer NOT NULL DEFAULT nextval('app.features_id_seq'::regclass),
"timestamp" bigint,
username character varying(20) COLLATE pg_catalog."default",
real_name character varying(20) COLLATE pg_catalog."default",
staff_name character varying(100) COLLATE pg_catalog."default",
reason character varying(500) COLLATE pg_catalog."default",
type character varying(100) COLLATE pg_catalog."default",
CONSTRAINT features_pkey PRIMARY KEY (id)
question from:
https://stackoverflow.com/questions/65598568/pg-insert-accepts-only-string-key-for-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…