11.4. Handling Huge Amounts of Data

If you have to work with more than just a few records, using INSERT is far too slow. As you have already learned, PostgreSQL provides a command called COPY, which you can use to insert more than just one record into a table at once.

In this section the PHP functions related to the COPY command will be discussed. You will also learn about the performance impact of using COPY.

Using COPY works slightly differently than working with a set of INSERT commands. Here's the next example:

 <?php $connstr = "dbname=phpbook user=postgres host=localhost"; $dbh = pg_connect($connstr); if ($dbh) {echo "connection to phpbook established ...<br>";} echo "starting process ...<br>\n"; echo "begin: ".date('Y-m-d H:i:s')."<br>\n"; ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.