summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSimon Holywell <[email protected]>2013-02-28 14:16:58 +0000
committerSimon Holywell <[email protected]>2013-02-28 14:16:58 +0000
commitbc56239e9a77ff8239ed04d20cdcfd6a854d4c19 (patch)
tree118ad21d049be216f71872678b0fcc67a356154a /docs
parentc3520a87373e81df80b437d1d7b3a824de08fb28 (diff)
Prepend PHP tag in docs
Diffstat (limited to 'docs')
-rw-r--r--docs/configuration.rst12
-rw-r--r--docs/connections.rst2
-rw-r--r--docs/models.rst9
-rw-r--r--docs/querying.rst44
-rw-r--r--docs/transactions.rst1
5 files changed, 68 insertions, 0 deletions
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 6bfd464..395a1eb 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -14,6 +14,7 @@ First, ``require`` the Idiorm source file:
.. code-block:: php
+ <?php
require_once 'idiorm.php';
Then, pass a *Data Source Name* connection string to the ``configure``
@@ -22,6 +23,7 @@ database. For more information, see the `PDO documentation`_.
.. code-block:: php
+ <?php
ORM::configure('sqlite:./example.db');
You may also need to pass a username and password to your database
@@ -30,6 +32,7 @@ For example, if you are using MySQL:
.. code-block:: php
+ <?php
ORM::configure('mysql:host=localhost;dbname=my_database');
ORM::configure('username', 'database_user');
ORM::configure('password', 'top_secret');
@@ -47,6 +50,7 @@ wish to modify and the value you wish to set it to.
.. code-block:: php
+ <?php
ORM::configure('setting_name', 'value_for_setting');
A shortcut is provided to allow passing multiple key/value pairs at
@@ -54,6 +58,7 @@ once.
.. code-block:: php
+ <?php
ORM::configure(array(
'setting_name_1' => 'value_for_setting_1',
'setting_name_2' => 'value_for_setting_2',
@@ -72,6 +77,7 @@ this:
.. code-block:: php
+ <?php
ORM::configure('mysql:host=localhost;dbname=my_database');
ORM::configure('username', 'database_user');
ORM::configure('password', 'top_secret');
@@ -81,6 +87,7 @@ configuration array shortcut:
.. code-block:: php
+ <?php
ORM::configure(array(
'connection_string' => 'mysql:host=localhost;dbname=my_database',
'username' => 'database_user',
@@ -97,6 +104,7 @@ See the `find_result_set()` documentation for more information.
.. code-block:: php
+ <?php
ORM::configure('return_result_sets', true); // returns result sets
@@ -118,6 +126,7 @@ the connection:
.. code-block:: php
+ <?php
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
PDO Error Mode
@@ -131,6 +140,7 @@ class constants defined by PDO. For example:
.. code-block:: php
+ <?php
ORM::configure('error_mode', PDO::ERRMODE_WARNING);
The default setting is ``PDO::ERRMODE_EXCEPTION``. For full details of
@@ -174,6 +184,7 @@ all tables. If your ID column is called ``primary_key``, use:
.. code-block:: php
+ <?php
ORM::configure('id_column', 'primary_key');
Setting: ``id_column_overrides``
@@ -185,6 +196,7 @@ the table, you can use the following configuration:
.. code-block:: php
+ <?php
ORM::configure('id_column_overrides', array(
'person' => 'person_id',
'role' => 'role_id',
diff --git a/docs/connections.rst b/docs/connections.rst
index 9a3a67a..bb9ea72 100644
--- a/docs/connections.rst
+++ b/docs/connections.rst
@@ -12,6 +12,7 @@ calls in the chain use the correct connection.
.. code-block:: php
+ <?php
// Default connection
ORM::configure('sqlite:./example.db');
@@ -51,6 +52,7 @@ query on *any* connection.
.. code-block:: php
+ <?php
// Using default connection, explicitly
$person = ORM::for_table('person')->find_one(5);
diff --git a/docs/models.rst b/docs/models.rst
index dbb4695..d72e27d 100644
--- a/docs/models.rst
+++ b/docs/models.rst
@@ -11,6 +11,7 @@ simply by accessing the property on the object directly:
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->find_one(5);
// The following two forms are equivalent
@@ -27,6 +28,7 @@ be returned.
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->create();
$person->first_name = 'Fred';
@@ -51,6 +53,7 @@ update multiple properties at once, by passing in an associative array:
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->find_one(5);
// The following two forms are equivalent
@@ -74,6 +77,7 @@ expressions using the ``set_expr`` method.
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->find_one(5);
$person->set('name', 'Bob Smith');
$person->age = 20;
@@ -92,6 +96,7 @@ instance. You then set values on the object as normal, and save it.
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->create();
$person->name = 'Joe Bloggs';
@@ -111,6 +116,7 @@ expressions using the ``set_expr`` method.
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->create();
$person->set('name', 'Bob Smith');
$person->age = 20;
@@ -129,6 +135,7 @@ created (or last saved), call the ``is_dirty`` method:
.. code-block:: php
+ <?php
$name_has_changed = $person->is_dirty('name'); // Returns true or false
Deleting records
@@ -139,6 +146,7 @@ method.
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->find_one(5);
$person->delete();
@@ -146,6 +154,7 @@ To delete more than one object from the database, build a query:
.. code-block:: php
+ <?php
$person = ORM::for_table('person')
->where_equal('zipcode', 55555)
->delete_many();
diff --git a/docs/querying.rst b/docs/querying.rst
index 6d83fff..d6a56e5 100644
--- a/docs/querying.rst
+++ b/docs/querying.rst
@@ -39,6 +39,7 @@ Bloggs":
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->where('name', 'Fred Bloggs')->find_one();
This roughly translates into the following SQL:
@@ -49,6 +50,7 @@ To find a single record by ID, you can pass the ID directly to the
.. code-block:: php
+ <?php
$person = ORM::for_table('person')->find_one(5);
Multiple records
@@ -67,12 +69,14 @@ To find all records in the table:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->find_many();
To find all records where the ``gender`` is ``female``:
.. code-block:: php
+ <?php
$females = ORM::for_table('person')->where('gender', 'female')->find_many();
As a result set
@@ -96,6 +100,7 @@ So for example instead of running this:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->find_many();
foreach ($people as $person) {
$person->age = 50;
@@ -106,6 +111,7 @@ You can simple do this instead:
.. code-block:: php
+ <?php
ORM::for_table('person')->find_result_set()
->set('age', 50)
->save();
@@ -118,12 +124,14 @@ over it just like an array.
.. code-block:: php
+ <?php
foreach(ORM::for_table('person')->find_result_set() as $record) {
echo $person->name;
}
.. code-block:: php
+ <?php
echo count(ORM::for_table('person')->find_result_set());
.. note::
@@ -140,6 +148,7 @@ instances. To do this substitute any call to ``find_many()`` with
.. code-block:: php
+ <?php
$females = ORM::for_table('person')->where('gender', 'female')->find_array();
This is useful if you need to serialise the the query output into a
@@ -154,6 +163,7 @@ query, call the ``count()`` method.
.. code-block:: php
+ <?php
$number_of_people = ORM::for_table('person')->count();
Filtering results
@@ -223,12 +233,14 @@ To add a ``WHERE ... LIKE`` clause, use:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->where_like('name', '%fred%')->find_many();
Similarly, to add a ``WHERE ... NOT LIKE`` clause, use:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->where_not_like('name', '%bob%')->find_many();
Set membership: ``where_in`` and ``where_not_in``
@@ -242,6 +254,7 @@ compare against. The second is an *array* of possible values.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->where_in('name', array('Fred', 'Joe', 'John'))->find_many();
Working with ``NULL`` values: ``where_null`` and ``where_not_null``
@@ -271,6 +284,7 @@ with preceding and following WHERE clauses with AND.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')
->where('name', 'Fred')
->where_raw('(`age` = ? OR `age` = ?)', array(20, 25))
@@ -300,6 +314,7 @@ equivalents.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->where('gender', 'female')->limit(5)->offset(10)->find_many();
Ordering
@@ -314,6 +329,7 @@ column name to sort by. The column names will be quoted.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->order_by_asc('gender')->order_by_desc('name')->find_many();
If you want to order by something other than a column name, then use the
@@ -322,6 +338,7 @@ If you want to order by something other than a column name, then use the
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->order_by_expr('SOUNDEX(`name`)')->find_many();
Grouping
@@ -336,12 +353,14 @@ times to add further columns.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->where('gender', 'female')->group_by('name')->find_many();
It is also possible to ``GROUP BY`` a database expression:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->where('gender', 'female')->group_by_expr("FROM_UNIXTIME(`time`, '%Y-%m')")->find_many();
Having
@@ -357,6 +376,7 @@ For example:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->group_by('name')->having_not_like('name', '%bob%')->find_many();
Result columns
@@ -367,12 +387,14 @@ your query. That is, calling:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT * FROM `person`;
The ``select`` method gives you control over which columns are returned.
@@ -382,12 +404,14 @@ many columns at once.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->select('name')->select('age')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT `name`, `age` FROM `person`;
Optionally, you may also supply a second argument to ``select`` to
@@ -395,12 +419,14 @@ specify an alias for the column:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->select('name', 'person_name')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT `name` AS `person_name` FROM `person`;
Column names passed to ``select`` are quoted automatically, even if they
@@ -408,12 +434,14 @@ contain ``table.column``-style identifiers:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->select('person.name', 'person_name')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT `person`.`name` AS `person_name` FROM `person`;
If you wish to override this behaviour (for example, to supply a
@@ -425,6 +453,7 @@ to specify many expressions at once.
.. code-block:: php
+ <?php
// NOTE: For illustrative purposes only. To perform a count query, use the count() method.
$people_count = ORM::for_table('person')->select_expr('COUNT(*)', 'count')->find_many();
@@ -432,6 +461,7 @@ Will result in the query:
.. code-block:: php
+ <?php
SELECT COUNT(*) AS `count` FROM `person`;
Shortcuts for specifying many columns
@@ -442,12 +472,14 @@ allow you to specify more than one column at once. For example:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->select_many('name', 'age')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT `name`, `age` FROM `person`;
To specify aliases you need to pass in an array (aliases are set as the
@@ -455,12 +487,14 @@ key in an associative array):
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->select_many(array('first_name' => 'name'), 'age', 'height')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT `name` AS `first_name`, `age`, `height` FROM `person`;
You can pass the the following styles into ``select_many`` and
@@ -468,6 +502,7 @@ You can pass the the following styles into ``select_many`` and
.. code-block:: php
+ <?php
select_many(array('alias' => 'column', 'column2', 'alias2' => 'column3'), 'column4', 'column5')
select_many('column', 'column2', 'column3')
select_many(array('column', 'column2', 'column3'), 'column4', 'column5')
@@ -477,12 +512,14 @@ do the following to get a neat select query including an expression:
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->select_many('name', 'age', 'height')->select_expr('NOW()', 'timestamp')->find_many();
Will result in the query:
.. code-block:: php
+ <?php
SELECT `name`, `age`, `height`, NOW() AS `timestamp` FROM `person`;
DISTINCT
@@ -493,12 +530,14 @@ query, add a call to ``distinct()`` to your query chain.
.. code-block:: php
+ <?php
$distinct_names = ORM::for_table('person')->distinct()->select('name')->find_many();
This will result in the query:
.. code-block:: php
+ <?php
SELECT DISTINCT `name` FROM `person`;
Joins
@@ -522,6 +561,7 @@ The table and column names will be automatically quoted. For example:
.. code-block:: php
+ <?php
$results = ORM::for_table('person')->join('person_profile', array('person.id', '=', 'person_profile.person_id'))->find_many();
It is also possible to specify the condition as a string, which will be
@@ -530,6 +570,7 @@ will **not** be escaped, and so this method should be used with caution.
.. code-block:: php
+ <?php
// Not recommended because the join condition will not be escaped.
$results = ORM::for_table('person')->join('person_profile', 'person.id = person_profile.person_id')->find_many();
@@ -542,6 +583,7 @@ method to control which columns get returned.
.. code-block:: php
+ <?php
$results = ORM::for_table('person')
->table_alias('p1')
->select('p1.*')
@@ -559,6 +601,7 @@ To return a minimum value of column, call the ``min()`` method.
.. code-block:: php
+ <?php
$min = ORM::for_table('person')->min('height');
The other functions (``AVG``, ``MAX`` and ``SUM``) work in exactly the
@@ -576,6 +619,7 @@ syntax, which will be used to bind the parameters to the query.
.. code-block:: php
+ <?php
$people = ORM::for_table('person')->raw_query('SELECT p.* FROM person p JOIN role r ON p.role_id = r.id WHERE r.name = :role', array('role' => 'janitor'))->find_many();
The ORM class instance(s) returned will contain data for all the columns
diff --git a/docs/transactions.rst b/docs/transactions.rst
index c32594d..d249421 100644
--- a/docs/transactions.rst
+++ b/docs/transactions.rst
@@ -6,6 +6,7 @@ it’s very easy to use PDO’s built-in methods:
.. code-block:: php
+ <?php
// Start a transaction
ORM::get_db()->beginTransaction();