From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001
From: admin Code Igniter uses a modified version of the Active Record Database Pattern.
-This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting.
-In some cases only one or two lines of code are necessary to perform a database action.
+ Code Igniter uses a modified version of the Active Record Database Pattern.
+This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting.
+In some cases only one or two lines of code are necessary to perform a database action.
Code Igniter does not require that each database table be its own class file. It instead provides a more simplified interface. Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax
@@ -182,7 +182,7 @@ $query = $this->db->get(); Multiple function calls can be made if you need several joins in one query. If you need something other than a natural JOIN you can specify it via the third parameter of the function.
+ If you need something other than a natural JOIN you can specify it via the third parameter of the function.
Options are: left, right, outer, inner, left outer, and right outer. Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by.
+ Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by.
The second parameter lets you set the direction of the result. Options are asc or desc or RAND() The first parameter is the table name, the second is the where clause. You can also use the where() or orwhere() functions instead of passing
+ The first parameter is the table name, the second is the where clause. You can also use the where() or orwhere() functions instead of passing
the data to the second parameter of the function:
Code Igniter's query caching system happens dynamically when your pages are viewed.
+ Code Igniter's query caching system happens dynamically when your pages are viewed.
When caching is enabled, the first time a web page is loaded, the query result object will
be serialized and stored in a text file on your server. The next time the page is loaded the cache file will be used instead of
accessing your database. Your database usage can effectively be reduced to zero for any pages that have been cached. Only read-type (SELECT) queries can be cached, since these are the only type of queries that produce a result.
+ Only read-type (SELECT) queries can be cached, since these are the only type of queries that produce a result.
Write-type (INSERT, UPDATE, etc.) queries, since they don't generate a result, will not be cached by the system. Cache files DO NOT expire. Any queries that have been cached will remain cached until you delete them. The caching system
-permits you clear caches associated with individual pages, or you can delete the entire collection of cache files.
+ Cache files DO NOT expire. Any queries that have been cached will remain cached until you delete them. The caching system
+permits you clear caches associated with individual pages, or you can delete the entire collection of cache files.
Typically you'll to use the housekeeping functions described below to delete cache files after certain
events take place, like when you've added new information to your database. Getting a performance gain as a result of caching depends on many factors.
+ Getting a performance gain as a result of caching depends on many factors.
If you have a highly optimized database under very little load, you probably won't see a performance boost.
-If your database is under heavy use you probably will see an improved response, assuming your file-system is not
+If your database is under heavy use you probably will see an improved response, assuming your file-system is not
overly taxed. Remember that caching simply changes how your information is retrieved, shifting it from being a database
operation to a file-system one. Code Igniter places the result of EACH query into its own cache file. Sets of cache files are further organized into
+ Code Igniter places the result of EACH query into its own cache file. Sets of cache files are further organized into
sub-folders corresponding to your controller functions. To be precise, the sub-folders are named identically to the
first two segments of your URI (the controller class name and function name). For example, let's say you have a controller called blog with a function called comments that
-contains three queries. The caching system will create a cache folder
+contains three queries. The caching system will create a cache folder
called blog+comments, into which it will write three cache files. If you use dynamic queries that change based on information in your URI (when using pagination, for example), each instance of
-the query will produce its own cache file. It's possible, therefore, to end up with many times more cache files than you have
+the query will produce its own cache file. It's possible, therefore, to end up with many times more cache files than you have
queries. Since cache files do not expire, you'll need to build deletion routines into your application. For example, let's say you have a blog
-that allows user commenting. Whenever a new comment is submitted you'll want to delete the cache files associated with the
-controller function that serves up your comments. You'll find two delete functions described below that help you
+that allows user commenting. Whenever a new comment is submitted you'll want to delete the cache files associated with the
+controller function that serves up your comments. You'll find two delete functions described below that help you
clear data. This function enables you to call PHP database functions that are not natively included in Code Igniter, in a platform independent manner.
-For example, lets say you want to call the mysql_get_client_info() function, which is not natively supported
+ This function enables you to call PHP database functions that are not natively included in Code Igniter, in a platform independent manner.
+For example, lets say you want to call the mysql_get_client_info() function, which is not natively supported
by Code Igniter. You could do so like this:
You must supply the name of the function, without the mysql_ prefix, in the first parameter. The prefix is added
-automatically based on which database driver is currently being used. This permits you to run the same function on different database platforms.
+automatically based on which database driver is currently being used. This permits you to run the same function on different database platforms.
Obviously not all function calls are identical between platforms, so there are limits to how useful this function can be in terms of portability. Any parameters needed by the function you are calling will be added to the second parameter. Code Igniter has a config file that lets you store your database connection values (username, password, database name, etc.).
+ Code Igniter has a config file that lets you store your database connection values (username, password, database name, etc.).
The config file is located at:
application/config/database.php The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store
-multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.)
+ The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store
+multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.)
under a single installation, you can set up a connection group for each, then switch between groups as needed.
For example, to set up a "test" environment you would do this: Then, to globally tell the system to use that group you would set this variable located in the config file: The "auto connect" feature will load and instantiate the database class with every page load.
+ The "auto connect" feature will load and instantiate the database class with every page load.
To enable "auto connecting", add the word database to the core array, as indicated in the following file: application/config/autoload.php If only some of your pages require database connectivity you can manually connect to your database by adding this
-line of code in any function where it is needed, or in your class constructor to make the database
+ If only some of your pages require database connectivity you can manually connect to your database by adding this
+line of code in any function where it is needed, or in your class constructor to make the database
available globally in that class. If the above function does not contain any information in the first parameter it will connect
+ If the above function does not contain any information in the first parameter it will connect
to the group specified in your database config file. For most people, this is the preferred method of use. Note: Change the words "group_one" and "group_two" to the specific group names you are connecting to (or
+ Note: Change the words "group_one" and "group_two" to the specific group names you are connecting to (or
you can pass the connection values as indicated above). By setting the second parameter to TRUE (boolean) the function will return the database object. The above get() function retrieves all the results from the supplied table.
+ The above get() function retrieves all the results from the supplied table.
The Active Record class contains a full compliment of functions
for working with data. 2. You can gather the field names associated with any query you run by calling the function
+ 2. You can gather the field names associated with any query you run by calling the function
from your query result object: Note: Replace field_name with the name of the column you are looking for, and replace
+ Note: Replace field_name with the name of the column you are looking for, and replace
table_name with the name of the table you are looking for. This is a simplified version of the $this->db->query() function. It ONLY returns TRUE/FALSE on success or failure.
-It DOES NOT return a database result set, nor does it set the query timer, or compile bind data, or store your query for debugging.
+It DOES NOT return a database result set, nor does it set the query timer, or compile bind data, or store your query for debugging.
It simply lets you submit a query. Most users will rarely use this function. It's a very good security practice to escape your data before submitting it into your database.
+ It's a very good security practice to escape your data before submitting it into your database.
Code Igniter has two functions that help you do this: This function returns a single result row. If your query has more than one row, it returns only the first row.
+ This function returns a single result row. If your query has more than one row, it returns only the first row.
The result is returned as an object. Here's a usage example: In addition, you can walk forward/backwards/first/last through your results using these variations:
diff --git a/user_guide/database/table_data.html b/user_guide/database/table_data.html
index 511cc7810..681193366 100644
--- a/user_guide/database/table_data.html
+++ b/user_guide/database/table_data.html
@@ -12,7 +12,7 @@
diff --git a/user_guide/database/transactions.html b/user_guide/database/transactions.html
index ef1f1a6e6..4677ed6ff 100644
--- a/user_guide/database/transactions.html
+++ b/user_guide/database/transactions.html
@@ -12,7 +12,7 @@
@@ -69,8 +69,8 @@ Transactions
Code Igniter's database abstraction allows you to use transactions with databases that support transaction-safe table types. In MySQL, you'll need
to be running InnoDB or BDB table types rather then the more common MyISAM. Most other database platforms support transactions natively. If you are not familiar with
-transactions we recommend you find a good online resource to learn about them for your particular database. The information below assumes you
+ If you are not familiar with
+transactions we recommend you find a good online resource to learn about them for your particular database. The information below assumes you
have a basic understanding of transactions.
Active Record Class
-
@@ -353,7 +353,7 @@ $this->db->orlike('body', $match);
-
+
$this->db->orderby();
-$this->db->orderby("title", "desc");
@@ -563,7 +563,7 @@ $this->db->delete('mytable', array('id' => $id));
// DELETE FROM mytable
-
// WHERE id = $id
diff --git a/user_guide/database/caching.html b/user_guide/database/caching.html
index 8a43268e9..ce5535c23 100644
--- a/user_guide/database/caching.html
+++ b/user_guide/database/caching.html
@@ -12,7 +12,7 @@
@@ -86,24 +86,24 @@ when caching is enabled. Do NOT load this class manually.
-
How Does Caching Work?
-Will Caching Improve Your Site's Performance?
-How are Cache Files Stored?
-Managing your Cache Files
$this->db->call_function();
-$this->db->call_function('get_client_info');
Database Configuration
-
$db['default']['db_debug'] = FALSE;
$db['default']['active_r'] = TRUE;
$db['test']['db_debug'] = FALSE;
$db['test']['active_r'] = TRUE;$active_group = "test";
@@ -108,15 +108,15 @@ for the primary connection, but it too can be renamed to something more relevant
Explanation of Values:
-
diff --git a/user_guide/database/connecting.html b/user_guide/database/connecting.html
index c057f69fe..ced947941 100644
--- a/user_guide/database/connecting.html
+++ b/user_guide/database/connecting.html
@@ -12,7 +12,7 @@
@@ -69,20 +69,20 @@ Connecting
Automatically Connecting
-Manually Connecting
-$this->load->database();
-
echo $row->title;
}
-
}
-
@@ -106,7 +106,7 @@ if ($this->db->field_exists('field_name', 'table_name'))
-
}
$this->db->simple_query();
Escaping Queries
-
-
$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")";
-$sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')";
diff --git a/user_guide/database/results.html b/user_guide/database/results.html
index a301bc3f9..bae8a75c7 100644
--- a/user_guide/database/results.html
+++ b/user_guide/database/results.html
@@ -12,7 +12,7 @@
@@ -119,7 +119,7 @@ Query Results
row()
-
$query = $this->db->query("YOUR QUERY");
@@ -161,7 +161,7 @@ Query Results
$row = $query->row_array(5);
-
+
Traditionally, transactions have required a fair amount of work to implement since they demand that you to keep track of your queries -and determine whether to commit or rollback based on the success or failure of your queries. This is particularly cumbersome with +and determine whether to commit or rollback based on the success or failure of your queries. This is particularly cumbersome with nested queries. In contrast, we've implemented a smart transaction system that does all this for you automatically (you can also manage your transactions manually if you choose to, but there's really no benefit).
diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html index f1692808f..cbc791537 100644 --- a/user_guide/database/utilities.html +++ b/user_guide/database/utilities.html @@ -12,7 +12,7 @@ @@ -193,7 +193,7 @@ if ($result !== FALSE)Permits you to generate a CSV file from a query result. The first parameter of the function must contain the result object from your query. +
Permits you to generate a CSV file from a query result. The first parameter of the function must contain the result object from your query. Example:
@@ -204,7 +204,7 @@ $query = $this->db->query("SELECT * FROM mytable");
echo $this->dbutil->csv_from_result($query);
-The second and third parameters allows you to +
The second and third parameters allows you to
set the delimiter and newline character. By default tabs are used as the delimiter and "\n" is used as a new line. Example:
Permits you to generate an XML file from a query result. The first parameter expects a query result object, the second
+ Permits you to generate an XML file from a query result. The first parameter expects a query result object, the second
may contain an optional array of config parameters. Example: Note: This features is only available for MySQL/MySQLi databases. Note: Due to the limited execution time and memory available to PHP, backing up very large
-databases may not be possible. If your database is very large you might need to backup directly from your SQL server
+databases may not be possible. If your database is very large you might need to backup directly from your SQL server
via the command line, or have your server admin do it for you if you do not have root privileges.
@@ -221,7 +221,7 @@ If you need to write the file use the File
$this->dbutil->xml_from_result($db_result)
-
@@ -251,7 +251,7 @@ If you need to write the file use the File
Usage Example
--
cgit v1.2.3-24-g4f1b