PHP ORM: Object-Relational Mapping for PHP
Installing PHP ORM into your web application
-
Obtain the most recent release of PHP ORM.
-
Unzip the package. Add the PHP ORM directories to your current web application.
The directory 'classes' should be at the root level of your web application.
-
There will be a directory called "configuration_files" located at the root of your
web application. Move this entire directory to the same level as public_html.
This file contains the database connection details; moving it to this directory level will
keep your database connection parameters away from public files. Your directory structure should resemble:
Edit this file to include the database connection details for your database environment. Note: Because this directory lies outside of your document root, you will only need to upload it once to your server! Add details for the production environment, upload the directory to production, and subsequent changes to your web application can be made and transferred without any need to edit the datbase connection details.
-
There will be two configuration files which will require editing. The first file is 'configuration_files/databaseConnection.xml'.
This file contains database connection parameters and can contain parameters for several applications (if, for example,
you have several distinct sites being run on one hosting account). At least one connection is required. Here's a sample:
<environments> <environment> <name>test_configuration</name> <engine>MySQL</engine> <host>localhost</host> <port>3306</port> <username>user</username> <password>password</password> <database>db_name</database> </environment>
The parameters 'host', 'port', 'username', 'password', and 'database' are the standard database connection parameters which are supplied to make an ordinary database connection. The parameter 'engine' is reserved for future use to enable database connections on varying engines with only a single change in configuration. The parameter 'name' is a name given to the database connection configuration.
A second configuration file is located in the same directory as your database connection classes: 'classes/databaseConnection/application_orm_configuration.xml'. This small file contains the name of the configuration which the classes in the same directory should use for their datbase connections. This file is simple and contains only one useful entry:<applicationConfiguration> <name>test_configuration</name> </applicationConfiguration>
The name of the application configuration is 'test_configuration' because that's what's listed in the first file. It doesn't matter what name you choose, as long as applicationConfiguration→name exists as one of the named environments. -
To generate ORM classes, navigate to the following path in your web application:
http://localhost:8080/<your application path>/classes/ClassGenerator/configuredDatabaseConnections.php
The example page is located here. Click the links for each table to "Generate Class". This will return the ORM Class file for the selected table. Rename each file to remove the ".txt" extension and save it to the "classes" directory.
- When you have added all of the ORM classes to your application's "classes" directory, you are ready to begin using PHP ORM for your web application! Once you are happy that the classes work and won't need to be regenerated, just delete the directory: "/classes/ClassGenerator/".
Thank you for your interest in PHP ORM! This framework is currently under development and is not yet
ready for the prime-time. Feel free to browse the documentation and check back soon for updates to the
tools, documentation, example uses, etc.