Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:40:49+00:00 2026-06-18T03:40:49+00:00

I have function in my PostgreSQL Server CREATE OR REPLACE FUNCTION edit_senti_meta_translation(_senti_id bigint, _meta_id

  • 0

I have function in my PostgreSQL Server

CREATE OR REPLACE FUNCTION edit_senti_meta_translation(_senti_id bigint, _meta_id bigint, _lang_code character, _meta_title character varying, _meta_note text)
  RETURNS boolean AS
$BODY$
BEGIN
    PERFORM
        senti.is_draft
    FROM
        senti, senti_meta
    WHERE
        senti.senti_id=_senti_id
    AND senti_meta.senti_id=senti.senti_id
    AND senti_meta.senti_id=_senti_id
    AND senti_meta.meta_id=_meta_id;
    IF FALSE THEN
        RETURN FALSE;
    END IF;
    BEGIN
        UPDATE senti_meta_translation
        SET meta_title=_meta_title, meta_note=_meta_note
        WHERE meta_id=_meta_id AND lang_code=_lang_code;
        IF FOUND THEN
            UPDATE senti_meta SET last_update=now() WHERE senti_id=_senti_id AND meta_id=_meta_id;
            RETURN TRUE;
        ELSE
            RETURN FALSE;
        END IF;
    END;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

Well, It’s working if i try in pgadmin3, and My record was updated(Work 100% as i expected) if i call this function

SELECT edit_senti_meta_translation(1, 41, 'eng', 'a', 'a');

But When i try to call the function using PHP(PDO Driver) It give me the result true or false, but The UPDATE is not running, My record is not updated.

$stmt = Database::getInstance()->prepare('SELECT * FROM edit_senti_meta_translation(:senti_id, :meta_id, :lang_code, :meta_title, :meta_note);');
$stmt->bindParam(':senti_id', $senti_id, PDO::PARAM_INT);
$stmt->bindParam(':meta_id', $meta_id, PDO::PARAM_INT);
$stmt->bindParam(':lang_code', $lang_code, PDO::PARAM_STR);
$stmt->bindParam(':meta_title', $meta_title, PDO::PARAM_STR);
$stmt->bindParam(':meta_note', $meta_note, PDO::PARAM_STR);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
return $stmt->fetchColumn(0);

Even when i change the first line in my php code

$stmt = Database::getInstance()->prepare("SELECT edit_senti_meta_translation(1, 41, 'eng', 'a', 'a');");

It give me the result(true/false) but the record is not updated.
This make me so confused

For info, i’m using PostgreSQL 8.4

One thing that makes me confused is when i call the function directly in pgadmin3, it give me the correct return with record updated, but when call it from PHP(PDO), it only give me return, but the record is not updated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:40:50+00:00Added an answer on June 18, 2026 at 3:40 am

    Well, after struggling with the problem, And @dmirkitanov reply with the idea why this may happen.

    It might be related with transactions, if, for example, this code runs
    in a transaction, and there is no commit after it

    I notice that on the PDO Singleton Class, some one in the project adding a new line.
    *See the commented line of code

    <?php
    
    include('config.database.php');
    
    class Database {
    
        protected static $instance = null;
    
        final private function __construct() {}
        final private function __destruct() {
            //self::$instance->commit();
            self::$instance = null;
        }
    
        final private function __clone() {}
    
        public static function getInstance() {
            if (self::$instance === null) {
                try {
                    self::$instance = new PDO(
                        'pgsql:host='   . DatabaseConfig::HOST . 
                        ';port='        . DatabaseConfig::PORT . 
                        ';dbname='      . DatabaseConfig::DBNAME . 
                        ';user='        . DatabaseConfig::USER . 
                        ';password='    . DatabaseConfig::PASSWORD
                    );
                    self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$instance->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
                    //self::$instance->beginTransaction();
                } catch (PDOException $e) {
                    self::$instance->rollBack();
                    die('Database connection could not be established.');
                }
            }
    
            return self::$instance;
        }
        public static function __callStatic($method, $args) {
            return call_user_func_array(array(self::instance(), $method), $args);
        }
    }
    ?>
    

    So as you can see, beginTransaction() is set in the getInstance(), but the commit() is set in __destruct()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PostgreSQL 8.4 on Linux. I have a function: CREATE OR REPLACE FUNCTION production.add_customer (
We have a function written in pl/sql(oracle) as below: CREATE OR REPLACE PROCEDURE folder_cycle_check
I have postgresql (in perlu) function getTravelTime(integer, timestamp), which tries to select data for
I have function some_func_1 which will create an object of type some_type and will
I have more than 50 databases hosted in my postgresql server. I need to
I have written a function in postgresql with one inpute parameter. I want to
I have this function in PostgreSQL, but I don't know how to return the
I have an PostgreSQL Function which returns me an XML where the whole infos
I am trying to create a trigger function in PostgreSQL that should check records
Is there any way to have a function in PostgreSQL return an arbitrary type?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.