Home Codeigniter Send Data/Parameter to PostgreSQL
Reply: 1

Codeigniter Send Data/Parameter to PostgreSQL

ian
1#
ian Published in 2017-09-14 04:18:46Z

I'am familiar with mysql server and now try to learn postgresql.

Before, I save/update data from CI using mssql store procedure sample:

my controller

$data = array(
  'name' => $_POST['name'],
);
$insert = $this->db->save($data);

my model

public function save($data){
        $sp = "insert ?";
        $result = $this->db->query($sp,$data);
        return $this->db->affected_rows();
    }

I'am try to implement that code to call postgresql function but it give me error like this

ERROR: syntax error at or near "insert" LINE 1: insert E'name'

this is my postgresql function

CREATE OR REPLACE FUNCTION insert(name varchar(50)) RETURNS refcursor AS $$
DECLARE 
    nama varchar(50);
BEGIN
    INSERT INTO dt_anggota VALUES(nama);
END;
$$ LANGUAGE PLPGSQL;

Whats wrong with my code or my function?

Thank You

ian
2#
ian Reply to 2017-09-15 08:45:46Z

I already found a solution my code is like this

$sp = "select 'function_name' (?)";
$result = $this->db->query($sp,$data);
return $this->db->affected_rows();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312155 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO