Alexander Schrijver schrieb:
Hi list,

I'm working on a project which uses a MySQL database to store some data. The
database looks something like this:

- id (PK)
- name
- sector_id -> Sectors (id)
- etc

- id (PK)
- company_id -> Companies (id)
- name
- etc

- id (PK)
- name
- etc

And we're using a Session to store references (not actual PHP references
ofcourse just the identifying integers) to these tables.

For example a list of companies and locations which are selected in the GUI is
kept in the session state.

The session would look something like this when filled up. The integers are the
PKs of the companies and sectors tables respectively.

Companies = Array (1,2,3,4,etc)
Sectors = Array (1,2,3,4,etc)

The problem is: when there are 2 clients one administrative and one user,
and the user has selected a company (or something else, it doesn't really
matter). And then the administrative user comes along and deletes the row which
the user just selected from the company table. There is an invalid reference in
the Session of the user.

I figured if I saved the session in the database and used constraints (foreign
keys) to enforce this. This could work. However, the PHP session abstraction
makes it very difficult to implement this properly. (I looked at

How do you guys deal with this problem?



Why don't you write a small function checking for invalid IDs and delete them and referenced subIDs? If you guess it's to hard/slow to find out all referenced subIDs you could change your Session array to an multi-dimensional array, with all referenced IDs on lower levels

array ( sector_id => array ( company_id => array (location_id) ) );


array ( 1 => array (17,4 => array(2)) would mean that loction 2 inside company 4 inside section 1 was selected. This way you only need to delete an old entry, and all referenced IDs dissapear


PHP General Mailing List (
To unsubscribe, visit:

Reply via email to