Qui sotto riporto l'output di uno script di sperimentazione dell'ORM
RedBeanPhp.
Some experiments with RedBeanPhp
Setting up the db...
DB connection established (line 62)
DB erased (line 66)
Categories creation and storing
OK - Stored category {"id":1,"name":"Art"} (line 80)
OK - Stored category {"id":2,"name":"History"} (line 80)
OK - Stored category {"id":3,"name":"Cinema"} (line 80)
OK - Stored category {"id":4,"name":"Environment"} (line 80)
Pictures creation and storing
One picture will not be stored because of its unsupported type.
An exception will be thrown.
OK - Stored picture: {"id":1,"height":640,"width":480,"description":"Beautiful place in the Alps","type":"jpeg"} (line 104)
OK - Stored picture: {"id":2,"height":480,"width":640,"description":"An old castle in Wales","type":"jpeg"} (line 104)
OK - Stored picture: {"id":3,"height":800,"width":200,"description":"Tears of Steel","type":"jpeg"} (line 104)
FAILED - Could not store picture {"id":0,"height":900,"width":1200,"description":"A picture sent by a colleague","type":"tiff"}: got Exception «Supported types are only: jpeg, gif, png»
(line 108)
OK - Stored picture: {"id":4,"height":300,"width":400,"description":"Big Buck Bunny","type":"gif"} (line 104)
OK - Stored picture: {"id":5,"height":600,"width":500,"description":"Latin America's Iguazu waterfalls","type":"png"} (line 104)
OK - Stored picture: {"id":6,"height":300,"width":200,"description":"Napoleon's portrait","type":"jpeg"} (line 104)
OK - Stored picture: {"id":7,"height":300,"width":200,"description":"Garibaldi's portrait","type":"jpeg"} (line 104)
Finding objects
OK - Found category from name: {"id":4,"name":"Environment"} (line 116)
OK - Found picture from description: {"id":"2","height":"480","width":"640","description":"An old castle in Wales","type":"jpeg"} (line 120)
Managing one-to-many relationships
OK - Updated picture with category: {"id":"2","height":"480","width":"640","description":"An old castle in Wales","type":"jpeg","category_id":"2"} (line 126)
Here we will update some rows with a loop
OK - Updated picture setting category: {"id":"1","height":"640","width":"480","description":"Beautiful place in the Alps","type":"jpeg","category_id":"4"} (line 142)
OK - Updated picture setting category: {"id":"5","height":"600","width":"500","description":"Latin America's Iguazu waterfalls","type":"png","category_id":"4"} (line 142)
Here we will write our UPDATE query using basic PDO prepared statements
OK - Updated historical pictures (with a prepared statement) (line 164)
Here we will use the own* property
OK - Loaded pictures using known ids (line 172)
OK - Set 'ownership' (line 176)
OK - Stored objects (line 178)
How to retrieve 'owned' objects
Picture {"id":"2","height":"480","width":"640","description":"An old castle in Wales","type":"jpeg","category_id":"2"} (line 184)
Picture {"id":"6","height":"300","width":"200","description":"Napoleon's portrait","type":"jpeg","category_id":"2"} (line 184)
Picture {"id":"7","height":"300","width":"200","description":"Garibaldi's portrait","type":"jpeg","category_id":"2"} (line 184)
Managing many-to-many relationships
Let's start by creating some people's records
OK - Stored person {"id":1,"name":"Alice"} (line 201)
OK - Stored person {"id":2,"name":"Bob"} (line 201)
OK - Stored person {"id":3,"name":"Charlie"} (line 201)
OK - Stored person {"id":4,"name":"Donna"} (line 201)
OK - Set information as shared for pictures (line 214)
Let's list persons connected to picture 1:
Person {"id":"2","name":"Bob"} (line 223)
Person {"id":"3","name":"Charlie"} (line 223)
Let's list pictures connected to person 2:
Picture {"id":"1","height":"640","width":"480","description":"Beautiful place in the Alps","type":"jpeg","category_id":"4"} (line 230)
Picture {"id":"2","height":"480","width":"640","description":"An old castle in Wales","type":"jpeg","category_id":"2"} (line 230)
Tagging
Tags are special many-to-many information pieces associated automatically with different kinds of objects.
We do not need to store them explicitly.
Stored tags for some pictures (line 241)
We can retrieve all the pictures that share the tag «beautiful sky»:
Picture {"id":"1","height":"640","width":"480","description":"Beautiful place in the Alps","type":"jpeg","category_id":"4"} (line 246)
Picture {"id":"2","height":"480","width":"640","description":"An old castle in Wales","type":"jpeg","category_id":"2"} (line 246)
We can retrieve all the pictures that share the tag «blender»
Picture {"id":"3","height":"800","width":"200","description":"Tears of Steel","type":"jpeg","category_id":"3"} (line 252)