Error in INSERT statement with PostgreSql and PHP -


i'm using postgresql, php , pdo. i'm getting error , dont know i'm doing wrong.

  • my environment is:

postgresql 9.3.6

ubuntu 14.04.2 lts

php 5.6.7

apache/2.4.12 (ubuntu)

the table i'm using this:

-- table: acesso.usuario  -- drop table acesso.usuario;  create table acesso.usuario (   usuarioidentificador serial not null,   usuariopessoafisicaidentificador integer,   usuarionome character varying(30) not null,   usuarionomecompleto character varying(90) not null,   usuariodescricao text,   usuariosenha character varying(32) not null,   usuariosenhaalterar bit(1) not null,   usuariosituacao bit(1) not null ) (   oids=false ); 

if execute @ pgadmin3

insert acesso.usuario(             usuariopessoafisicaidentificador, usuarionome,              usuarionomecompleto, usuariodescricao, usuariosenha, usuariosenhaalterar,              usuariosituacao)     values (null, '', '',              null, '', '1', '1'             ); 

i got query returned successfully: 1 row affected, 82 ms execution time.

so i'm trying same php:

try {             $query ="             insert acesso.usuario(             usuariopessoafisicaidentificador, usuarionome,              usuarionomecompleto, usuariodescricao, usuariosenha, usuariosenhaalterar,              usuariosituacao)     values (null, '', '',              null, '', '1', '1'             ); ";              $this->statement = $query;             $conn = $this->getconnection();              $query = $conn->prepare($this->statement, [\pdo::attr_cursor => \pdo::cursor_scroll]);              $result = $query->execute();          } catch (\exception $e) {             echo $e->getmessage() . "  <br> " . $e->getcode();              var_dump($query);             die();             return false;         } 

i'm getting output:

sqlstate[42601]: syntax error: 7 error: syntax error @ or near "insert" line 2: insert acesso.usuario( ^ 42601object(pdostatement)#14 (1) { ["querystring"]=> string(291) " insert acesso.usuario( usuariopessoafisicaidentificador, usuarionome, usuarionomecompleto, usuariodescricao, usuariosenha, usuariosenhaalterar, usuariosituacao) values (null, '', '', null, '', '1', '1' ); " }

i'm trying find out happening.

do know it?

thank anyway.

as query insert (as opposed select), can't mapped onto cursor. problem in attributes passed prepare:

 [\pdo::attr_cursor => \pdo::cursor_scroll] 

internally, pdo generates query starting postgres:

declare pdo_crsr_00000001 scroll cursor hold   insert acesso.usuario(... 

and documented in declare, query follows must select or values command, why parser yields syntax error when finds insert there instead.

the solution remove second argument:

$query = $conn->prepare($this->statement); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -