使用for php语句插入postgres db

I'm writing a code with this function:

function foo() {

    $input = array('bar');

    for ($i=0;$i<1000;$i++) {

        $db=connection_pgsql() or die('Connessione al DBMS non riuscita');

            pg_prepare( "run","INSERT INTO tab1(name) VALUES  ($1)");
            pg_execute("run",$input);

            pg_prepare( "run","INSERT INTO tab2(name) VALUES  ($1)");
            pg_execute("run",$input);

            pg_prepare( "run","INSERT INTO tab3(name) VALUES  ($1)");
            pg_execute("run",$input);

        pg_close($db);


    }
}   

After the execution of this function there are only

20 rows in tab1, 20 rows in tab2 and 20 rows in tab3

and not

1000 rows in tab1, 1000 rows in tab2 and 1000 rows in tab3.

Is it a problem of php or postgresql configuration?

You're not checking for errors.

Check the return value of functions and use the error info functions provided by PHP.

See:

You can also check the PostgreSQL error logs.

It's much clearer if you use PDO; see e.g. How is a Postgres "RAISE EXCEPTION" converted into a PDOException? .

Also, don't open and close connections each loop iteration like this, the performance will be awful. Preferably do all the work in a single transaction on a single connection.

check the resource returned or at least if it is not false. Look at docs example, you should not just pg_execute("run",$input);, but

$result = pg_execute("run",$input);

so you can run

var_dump($result);

This way you will see full dump of value returned on your html page.