Database Reference
In-Depth Information
the customer still valued? That would depend on the business reason for the evalu-
ation.
Try the following example:
<?php
$db = pg_connect('...');
pg_query('UPDATE customer SET valued_customer
= true WHERE balance > 6000;', $db);
pg_close($db);
?>
This is simpler, has transactional integrity, and works for an incredibly large number
of customers. Why point out such a simple and obvious example? Because many
development frameworks work the "wrong" way by default. The code generator will
produce some equivalent form of this example in the interest of being cross-platform,
predictable, and easy to integrate into a simple design model.
This method promotes terrible practices. For systems that have a very low number
of concurrent transactions, you will probably see what you would expect, but as con-
currency increases, the number of unintended behaviors also increases.
The second example exposes a better philosophy: operate on columns, not rows,
leave the data on the server, and let the database do the transactional work for you.
That's what the database was made for.
More basics
It helps to have some basic background information before starting to program for
the server. In the next few sections, we will explore the general technical environ-
ment in which you will be working. We will cover a lot of information, but don't worry
too much about remembering it all right now. Just try to pick up the general idea.
Transactions
The default transaction isolation level in PostgreSQL is called Read Committed .
This means that if multiple transactions attempt to modify the same data, they must
wait for each other to finish before acting upon the resulting data. They wait in a
Search WWH ::




Custom Search