<p>Does anyone have some good hints for writing test code for database-backend development where there is a heavy dependency on state?</p>

<p>Specifically, I want to write tests for code that retrieve records from the database, but the answers will depend on the data in the database (which may change over time).</p>

<p>Do people usually make a separate development system with a 'frozen' database so that any given function should always return the exact same result set?</p>

<p>I am quite sure this is not a new issue, so I would be very interested to learn from other people's experience.</p>

<p>Are there good articles out there that discuss this issue of web-based development in general?</p>

<p>I usually write PHP code, but I would expect all of these issues are largely language and framework agnostic.</p>

You should look into DBUnit, or try to find a PHP equivalent (there must be one out there).  You can use it to prepare the database with a specific set of data which represents your test data, and thus each test will no longer depend on the database and some existing state.  This way, each test is self contained and will not break during further database usage.
Update: A quick google search showed a
DB unit extension
for PHPUnit.