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 8111887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:17:23+00:00 2026-06-06T02:17:23+00:00

Using PHP 5.3.3, PostgreSQL 8.4.11, pgbouncer 1.3.4 (in session mode) on CentOS 6.2 I’m

  • 0

Using PHP 5.3.3, PostgreSQL 8.4.11, pgbouncer 1.3.4 (in session mode) on CentOS 6.2 I’m trying to execute several SQL commands and fetch the results by a PHP script.

When I copy the commands from script to psql prompt they work flawlessly and return 12 rows:

enter image description here

But when I run from script I get the error:

SQLSTATE[42601]: Syntax error: 7 ERROR: cannot insert multiple commands into a prepared statement

Any help please?

Below is my failing PHP code, I tried using $db->query() instead of $db->prepare/execute too:

try {
        $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
        $db = new PDO(sprintf('pgsql:host=%s port=%u; dbname=%s',
                DBHOST, DBPORT, DBNAME), DBUSER, DBPASS, $options);

        $sth = $db->prepare("
            start transaction;
            create temporary table temp_ids (id varchar not null) on commit drop;
            insert into temp_ids (id)
                    select id
                    from pref_money
                    where yw = to_char(current_timestamp - interval '1 week', 'IYYY-IW')
                    order by money
                    desc limit 10;

            create temporary table temp_rids (rid integer not null) on commit drop;
            insert into temp_rids (rid)
                    select rid
                    from pref_cards
                    where stamp > now() - interval '1 day' and
                    id in (select id from temp_ids) and
                    bid = 'Мизер' and
                    trix > 0;

            SELECT r.rid, r.cards, to_char(r.stamp, 'DD.MM.YYYY HH24:MI') as day,
                    c.bid, c.trix, c.pos, c.money, c.last_ip, c.quit,
                    u.id, u.first_name, u.avatar, u.female, u.city, u.vip > CURRENT_DATE as vip
                    FROM pref_rounds r, pref_cards c, pref_users u
                    WHERE u.id = c.id and
                        r.rid = c.rid and
                        r.rid in (select rid from temp_rids)
                    order by rid, pos;
            commit;
        ");
        $sth->execute();
        while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
              # stuff a JSON object
        }
} catch (Exception $e) {
        exit('Database problem: ' . $e->getMessage());
}
  • 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-06T02:17:25+00:00Added an answer on June 6, 2026 at 2:17 am

    I’ve got a tip at the mailing list to get rid of the temp. tables and it works for me:

    select r.rid, r.cards, to_char(r.stamp, 'DD.MM.YYYY HH24:MI') as day,
        c.bid, c.trix, c.pos, c.money, c.last_ip, c.quit,
        u.id, u.first_name, u.avatar, u.female, u.city, u.vip > CURRENT_DATE as vip
        from pref_rounds r, pref_cards c, pref_users u
        where u.id = c.id and
        r.rid = c.rid and
        r.rid in (
            select rid
                from pref_cards
                where stamp > CURRENT_TIMESTAMP - interval '1 day' and
                id in (
                    select id
                        from pref_money
                        where yw = to_char(CURRENT_TIMESTAMP - interval '1 week', 'IYYY-IW')
                        order by money
                        desc limit 10) and
                       bid = 'Misere' and
                       trix > 0
        )
        order by r.rid, c.pos
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to setup an Apache/PHP/Postgresql server locally on my machine. I'm using Windows
In PHP 5.4.1 i am using native PostgreSQL driver to connect to the SQL
I'm developing a PHP application using CodeIgniter as the framework, and PostgreSQL as the
Using PHP I'm trying to download/save the following image: http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428 When you load this
Using PHP 5.2.4 and the OpenSSL 0.9.8g module I am trying to create a
Using php I am trying to get some data from a .csv file which
I'm creating a web app using PHP and PostgreSQL. Database are too big and
I'm trying to do an association of 5 objects with Doctrine2 (PHP). I'm using
I'm having trouble figuring out this query. I'm using PHP and postgresql 9.1. I
I'm using PHP PDO with PostgreSQL for a new project. Given the following function,

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.