postgresql - The function pg_query() gives an error in php -


i want insert data in pgsql database. function pg_query() gives error when want insert data. error is:

warning: pg_query() [function.pg-query]: query failed: error: array value must start "{" or dimension information line 1: insert demo_insert(id, name) values ('1234', 'abcd') ^ in c:\wamp\www\netbeansprojects\phpproject1\index1.php on line 19 

my code follows:

<?php         require_once "connection.php";     //page connection database      pg_set_client_encoding($dbconn, "unicode");      //$dbconn variable pg_connect() executed      $id="1234";      $name="abcd";      $query = "insert demo_insert(id, name) values ('$id', '$name')";       $result = pg_query($dbconn, $query);      if($result)     {         echo "1 row inserted";     } ?> 

can please tell me solution of error?

it looks 1 of columns array type, not "normal" type. show table definitions?

offtopic: when using input parameters, have avoid sql injection. easiest solution using pg_query_params() instead of pg_query():

<?php     $id="1234";      $name="abcd";     // placeholders $1 , $2:     $query = "insert demo_insert(id, name) values ($1, $2)";      // array content:     $result = pg_query_params($dbconn, $query, array($id, $name));  ?> 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -