From 114ab0988e20ac6be39ad363ff897a1a3b85e565 Mon Sep 17 00:00:00 2001
From: Razican CodeIgniter 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.
-CodeIgniter 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 -is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.
+is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system. -Note: If you intend to write your own queries you can disable this class in your database config file, allowing the core database library and adapter to utilize fewer resources.
Note: If you intend to write your own queries you can disable this class in your database config file, allowing the core database library and adapter to utilize fewer resources.
Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table:
+Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table:
$query = $this->db->get('mytable');
@@ -126,7 +126,7 @@ $this->db->select('title, content, date');
$query = $this->db->get('mytable');
// Produces: SELECT title, content, date FROM mytable
-Note: If you are selecting all (*) from a table you do not need to use this function. When omitted, CodeIgniter assumes you wish to SELECT *
+Note: If you are selecting all (*) from a table you do not need to use this function. When omitted, CodeIgniter assumes you wish to SELECT *
$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.
Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
@@ -351,7 +351,7 @@ $this->db->or_where('id >', $id);
$this->db->like('title', 'match');
@@ -278,7 +278,7 @@ $this->db->or_where('id >', $id);
$this->db->where_in();
-
$names = array('Frank', 'Todd', 'James');
If you want to control where the wildcard (%) is placed, you can use an optional third argument. Your options are 'before', 'after' and 'both' (which is the default).
$this->db->where_in('username', $names);
@@ -322,7 +322,7 @@ $this->db->or_where('id >', $id);
$this->db->like('title', 'match');
+ // WHERE title LIKE '%match%' AND body LIKE '%match%
$this->db->like('body', 'match');
- // WHERE title LIKE '%match%' AND body LIKE '%match%$this->db->like('title', 'match', 'before');
+
@@ -340,7 +340,7 @@ $this->db->or_where('id >', $id);
$array = array('title' => $match, 'page1' => $match, 'page2' => $match);
$this->db->like($array);
-
// WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'
// WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'
$this->db->or_like('body', $match);
-
// WHERE title LIKE '%match%' OR body LIKE '%match%'
+
// WHERE title LIKE '%match%' OR body LIKE '%match%'
@@ -367,7 +367,7 @@ $this->db->or_like('body', $match);
$this->db->like('title', 'match');
+// WHERE title LIKE '%match% OR body NOT LIKE '%match%'
$this->db->or_not_like('body', 'match');
-// WHERE title LIKE '%match% OR body NOT LIKE '%match%'
Permits you to write the GROUP BY portion of your query:
@@ -385,7 +385,7 @@ $this->db->or_not_like('body', 'match');Adds the "DISTINCT" keyword to a query
+Adds the "DISTINCT" keyword to a query
$this->db->distinct();
@@ -409,16 +409,16 @@ $this->db->having('user_id', 45);
$this->db->get('table');
@@ -397,7 +397,7 @@ $this->db->or_not_like('body', 'match');
// Produces: HAVING user_id = 45
-$this->db->having('user_id', 45);
+$this->db->having('user_id', 45);
// Produces: HAVING user_id = 45
// Produces: HAVING title = 'My Title', id < 45
If you are using a database that CodeIgniter escapes queries for, you can prevent escaping content by passing an optional third argument, and setting it to FALSE.
-Identical to having(), only separates multiple clauses with "OR". 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 random. $this->db->having('user_id', 45);
+$this->db->having('user_id', 45);
// Produces: HAVING `user_id` = 45 in some databases such as MySQL
- $this->db->having('user_id', 45, FALSE);
+ $this->db->having('user_id', 45, FALSE);
// Produces: HAVING user_id = 45$this->db->or_having();
$this->db->order_by();
$this->db->order_by("title", "desc");
@@ -455,12 +455,12 @@ $this->db->limit(10);
$this->db->limit(10, 20);
-// Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
+// Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
Permits you to determine the number of rows in a particular Active Record query. Queries will accept Active Record restrictors such as where(), or_where(), like(), or_like(), etc. Example:
+Permits you to determine the number of rows in a particular Active Record query. Queries will accept Active Record restrictors such as where(), or_where(), like(), or_like(), etc. Example:
echo $this->db->count_all_results('my_table');
// Produces an integer, like 25
@@ -472,7 +472,7 @@ echo $this->db->count_all_results();
$this->db->count_all();
-Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:
+Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:
echo $this->db->count_all('my_table');
@@ -485,7 +485,7 @@ echo $this->db->count_all_results();
$this->db->insert();
Generates an insert string based on the data you supply, and runs the query. You can either pass an
-array or an object to the function. Here is an example using an array:
+array or an object to the function. Here is an example using an array:
$data = array(
@@ -505,9 +505,9 @@ $this->db->insert('mytable', $data);
/*
class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
+ var $title = 'My Title';
+ var $content = 'My Content';
+ var $date = 'My Date';
}
*/
@@ -523,7 +523,7 @@ $this->db->insert('mytable', $object);
$this->db->insert_batch();
Generates an insert string based on the data you supply, and runs the query. You can either pass an
-array or an object to the function. Here is an example using an array:
+array or an object to the function. Here is an example using an array:
$data = array(
@@ -541,7 +541,7 @@ $data = array(
$this->db->update_batch('mytable', $data);
-// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
+// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
The first parameter will contain the table name, the second is an associative array of values.
@@ -588,9 +588,9 @@ $this->db->insert('mytable');
/*
class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
+ var $title = 'My Title';
+ var $content = 'My Content';
+ var $date = 'My Date';
}
*/
@@ -606,7 +606,7 @@ $this->db->insert('mytable');
Updating Data
$this->db->update();
-Generates an update string and runs the query based on the data you supply. You can pass an
+
Generates an update string and runs the query based on the data you supply. You can pass an
array or an object to the function. Here is an example using
an array:
@@ -630,9 +630,9 @@ $this->db->update('mytable', $data);
/*
class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
+ var $title = 'My Title';
+ var $content = 'My Content';
+ var $date = 'My Date';
}
*/
@@ -711,7 +711,7 @@ $this->db->truncate('mytable');
Method Chaining
-Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:
+Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:
$this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20);
@@ -752,14 +752,14 @@ $this->db->get('tablename');
$this->db->select('field2');
$this->db->get('tablename');
-//Generates: SELECT `field1`, `field2` FROM (`tablename`)
+//Generates: SELECT `field1`, `field2` FROM (`tablename`)
$this->db->flush_cache();
$this->db->select('field2');
$this->db->get('tablename');
-//Generates: SELECT `field2` FROM (`tablename`)
+//Generates: SELECT `field2` FROM (`tablename`)
Note: The following statements can be cached: select, from, join, where, like, group_by, having, order_by, set
diff --git a/user_guide/database/caching.html b/user_guide/database/caching.html
index 3f4ef2bc3..76a91216d 100644
--- a/user_guide/database/caching.html
+++ b/user_guide/database/caching.html
@@ -62,7 +62,7 @@ Database Caching Class
The Database Caching Class permits you to cache your queries as text files for reduced database load.
Important: This class is initialized automatically by the database driver
-when caching is enabled. Do NOT load this class manually.
+when caching is enabled. Do NOT load this class manually.
Also note: Not all query result functions are available when you use caching. Please read this page carefully.
@@ -84,12 +84,12 @@ when caching is enabled. Do NOT load this class manually.
CodeIgniter'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.
+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.
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
+
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 want 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.
@@ -99,33 +99,33 @@ 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.
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
-overly taxed. Remember that caching simply changes how your information is retrieved, shifting it from being a database
+overly taxed. Remember that caching simply changes how your information is retrieved, shifting it from being a database
operation to a file-system one.
In some clustered server environments, for example, caching may be detrimental since file-system operations are so intense.
On single servers in shared environments, caching will probably be beneficial. Unfortunately there is no
-single answer to the question of whether you should cache your database. It really depends on your situation.
+single answer to the question of whether you should cache your database. It really depends on your situation.
How are Cache Files Stored?
-CodeIgniter 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
+
CodeIgniter 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.
Managing your Cache Files
-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
+
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
clear data.
@@ -155,8 +155,8 @@ pertain to run-time operations.
$this->db->cache_on() / $this->db->cache_off()
-Manually enables/disables caching. This can be useful if you want to
-keep certain queries from being cached. Example:
+Manually enables/disables caching. This can be useful if you want to
+keep certain queries from being cached. Example:
// Turn caching on
@@ -177,9 +177,9 @@ $query = $this->db->query("SELECT * FROM another_table");
Deletes the cache files associated with a particular page. This is useful if you need to clear caching after you update your database.
-The caching system saves your cache files to folders that correspond to the URI of the page you are viewing. For example, if you are viewing
+
The caching system saves your cache files to folders that correspond to the URI of the page you are viewing. For example, if you are viewing
a page at example.com/index.php/blog/comments, the caching system will put all cache files associated with it in a folder
-called blog+comments. To delete those particular cache files you will use:
+called blog+comments. To delete those particular cache files you will use:
$this->db->cache_delete('blog', 'comments');
@@ -188,7 +188,7 @@ called blog+comments. To delete those particular cache files you wil
$this->db->cache_delete_all()
-Clears all existing cache files. Example:
+Clears all existing cache files. Example:
$this->db->cache_delete_all();
diff --git a/user_guide/database/call_function.html b/user_guide/database/call_function.html
index 3e0c78d3d..7f294401e 100644
--- a/user_guide/database/call_function.html
+++ b/user_guide/database/call_function.html
@@ -63,13 +63,13 @@ Custom Function Calls
This function enables you to call PHP database functions that are not natively included in CodeIgniter, 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 CodeIgniter. You could do so like this:
+by CodeIgniter. You could do so like this:
$this->db->call_function('get_client_info');
-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.
+
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.
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.
@@ -77,7 +77,7 @@ Obviously not all function calls are identical between platforms, so there are l
$this->db->call_function('some_function', $param1, $param2, etc..);
-Often, you will either need to supply a database connection ID or a database result ID. The connection ID can be accessed using:
+Often, you will either need to supply a database connection ID or a database result ID. The connection ID can be accessed using:
$this->db->conn_id;
diff --git a/user_guide/database/configuration.html b/user_guide/database/configuration.html
index 51d11c9f2..b34705410 100644
--- a/user_guide/database/configuration.html
+++ b/user_guide/database/configuration.html
@@ -74,7 +74,7 @@ $db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
-$db['default']['cachedir'] = "";
+$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['default']['swap_pre'] = "";
@@ -82,7 +82,7 @@ $db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
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.)
+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:
@@ -95,7 +95,7 @@ $db['test']['dbprefix'] = "";
$db['test']['pconnect'] = TRUE;
$db['test']['db_debug'] = FALSE;
$db['test']['cache_on'] = FALSE;
-$db['test']['cachedir'] = "";
+$db['test']['cachedir'] = "";
$db['test']['char_set'] = "utf8";
$db['test']['dbcollat'] = "utf8_general_ci";
$db['test']['swap_pre'] = "";
@@ -107,7 +107,7 @@ $db['test']['stricton'] = FALSE;
$active_group = "test";
-Note: The name "test" is arbitrary. It can be anything you want. By default we've used the word "default"
+
Note: The name "test" is arbitrary. It can be anything you want. By default we've used the word "default"
for the primary connection, but it too can be renamed to something more relevant to your project.
Active Record
@@ -126,21 +126,21 @@ for the primary connection, but it too can be renamed to something more relevant
- password - The password used to connect to the database.
- database - The name of the database you want to connect to.
- dbdriver - The database type. ie: mysql, postgres, odbc, etc. Must be specified in lower case.
-- dbprefix - An optional table prefix which will added to the table name when running Active Record queries. This permits multiple CodeIgniter installations to share one database.
+- dbprefix - An optional table prefix which will added to the table name when running Active Record queries. This permits multiple CodeIgniter installations to share one database.
- pconnect - TRUE/FALSE (boolean) - Whether to use a persistent connection.
- db_debug - TRUE/FALSE (boolean) - Whether database errors should be displayed.
- cache_on - TRUE/FALSE (boolean) - Whether database query caching is enabled, see also Database Caching Class.
- cachedir - The absolute server path to your database query cache directory.
- char_set - The character set used in communicating with the database.
-- dbcollat - The character collation used in communicating with the database.
Note: For MySQL and MySQLi databases, this setting is only used as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7. There is an incompatibility in PHP with mysql_real_escape_string() which can make your site vulnerable to SQL injection if you are using a multi-byte character set and are running versions lower than these. Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
-- swap_pre - A default table prefix that should be swapped with dbprefix. This is useful for distributed applications where you might run manually written queries, and need the prefix to still be customizable by the end user.
+- dbcollat - The character collation used in communicating with the database.
Note: For MySQL and MySQLi databases, this setting is only used as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7. There is an incompatibility in PHP with mysql_real_escape_string() which can make your site vulnerable to SQL injection if you are using a multi-byte character set and are running versions lower than these. Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
+- swap_pre - A default table prefix that should be swapped with dbprefix. This is useful for distributed applications where you might run manually written queries, and need the prefix to still be customizable by the end user.
- autoinit - Whether or not to automatically connect to the database when the library loads. If set to false, the connection will take place prior to executing the first query.
- stricton - TRUE/FALSE (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL while developing an application.
-- port - The database port number. To use this value you have to add a line to the database config array.
$db['default']['port'] = 5432;
+ - port - The database port number. To use this value you have to add a line to the database config array.
$db['default']['port'] = 5432;
Note: Depending on what database platform you are using (MySQL, Postgres, etc.) -not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and +not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and the database name will be the path to your database file. The information above assumes you are using MySQL.
diff --git a/user_guide/database/connecting.html b/user_guide/database/connecting.html index bb1b401f9..1a74f5571 100644 --- a/user_guide/database/connecting.html +++ b/user_guide/database/connecting.html @@ -84,8 +84,8 @@ to the group specified in your database config file. For most people, this is thBy setting the second parameter to TRUE (boolean) the function will return the database object.
When you connect this way, you will use your object name to issue commands rather than the syntax used throughout this guide. In other words, rather than issuing commands with:
+When you connect this way, you will use your object name to issue commands rather than the syntax used throughout this guide. In other words, rather than issuing commands with:
$this->db->query();
$this->db->result();
etc...
The following page contains example code showing how the database class is used. For complete details please +
The following page contains example code showing how the database class is used. For complete details please read the individual pages describing each function.
@@ -73,7 +73,7 @@ read the individual pages describing each function.Once loaded the class is ready to be used as described below.
-Note: If all your pages require database access you can connect automatically. See the connecting page for details.
+Note: If all your pages require database access you can connect automatically. See the connecting page for details.
The above result() function returns an array of objects. Example: $row->title
+The above result() function returns an array of objects. Example: $row->title
The above result_array() function returns an array of standard array indexes. Example: $row['title']
+The above result_array() function returns an array of standard array indexes. Example: $row['title']
The above row() function returns an object. Example: $row->name
+The above row() function returns an object. Example: $row->name
The above row_array() function returns an array. Example: $row['name']
+The above row_array() function returns an array. Example: $row['name']
Sometimes it's helpful to know whether a particular field exists before performing an action. -Returns a boolean TRUE/FALSE. Usage example:
+Returns a boolean TRUE/FALSE. Usage example:
if ($this->db->field_exists('field_name', 'table_name'))
@@ -101,7 +101,7 @@ if ($this->db->field_exists('field_name', 'table_name'))
}
-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.
diff --git a/user_guide/database/forge.html b/user_guide/database/forge.html index cad2cf26f..bbef053e4 100644 --- a/user_guide/database/forge.html +++ b/user_guide/database/forge.html @@ -151,7 +151,7 @@ already be running, since the forge class relies on it. ),After the fields have been defined, they can be added using $this->dbforge->add_field($fields); followed by a call to the create_table() function.
+After the fields have been defined, they can be added using $this->dbforge->add_field($fields); followed by a call to the create_table() function.
The add fields function will accept the above array.
Generally speaking, you'll want your table to have Keys. This is accomplished with $this->dbforge->add_key('field'). An optional second parameter set to TRUE will make it a primary key. Note that add_key() must be followed by a call to create_table().
-Multiple column non-primary keys must be sent as an array. Sample output below is for MySQL.
+Multiple column non-primary keys must be sent as an array. Sample output below is for MySQL.
$this->dbforge->add_key('blog_id', TRUE);
// gives PRIMARY KEY `blog_id` (`blog_id`)
@@ -187,7 +187,7 @@ already be running, since the forge class relies on it.
Executes a DROP TABLE sql
$this->dbforge->drop_table('table_name');
- // gives DROP TABLE IF EXISTS table_name
Executes a TABLE rename
$this->dbforge->rename_table('old_table_name', 'new_table_name');
@@ -200,7 +200,7 @@ already be running, since the forge class relies on it.
Used to remove a column from a table.
$this->dbforge->drop_column('table_name', 'column_to_drop');
Displays the number of affected rows, when doing "write" type queries (insert, update, etc.).
-Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the -correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file.
+Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the +correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file.
Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:
+Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:
echo $this->db->count_all('my_table');
// Produces an integer, like 25
@@ -90,11 +90,11 @@ correct number of affected rows. By default this hack is enabled but it can be
$this->db->last_query();
-Returns the last query that was run (the query string, not the result). Example:
+Returns the last query that was run (the query string, not the result). Example:
$str = $this->db->last_query();
-// Produces: SELECT * FROM sometable....
+// Produces: SELECT * FROM sometable....
@@ -109,7 +109,7 @@ correct number of affected rows. By default this hack is enabled but it can be
$str = $this->db->insert_string('table_name', $data);
-The first parameter is the table name, the second is an associative array with the data to be inserted. The above example produces:
+The first parameter is the table name, the second is an associative array with the data to be inserted. The above example produces:
INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com')
Note: Values are automatically escaped, producing safer queries.
diff --git a/user_guide/database/index.html b/user_guide/database/index.html index fa3548cf1..594de80dd 100644 --- a/user_guide/database/index.html +++ b/user_guide/database/index.html @@ -63,7 +63,7 @@ Database Library structures and Active Record patterns. The database functions offer clear, simple syntax.$this->db->query('YOUR QUERY HERE');
The query() function returns a database result object when "read" type queries are run, -which you can use to show your results. When "write" type queries are run it simply returns TRUE or FALSE -depending on success or failure. When retrieving data you will typically assign the query to your own variable, like this:
+which you can use to show your results. When "write" type queries are run it simply returns TRUE or FALSE +depending on success or failure. When retrieving data you will typically assign the query to your own variable, like this:$query = $this->db->query('YOUR QUERY HERE');
This is a simplified version of the $this->db->query() function. It ONLY returns TRUE/FALSE on success or failure. +
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 simply lets you submit a query. Most users will rarely use this function.
@@ -100,16 +100,16 @@ CodeIgniter has three methods that help you do this:$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")";
$sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')";
$search = '20% raise';
@@ -130,7 +130,7 @@ $this->db->query($sql, array(3, 'live', 'Rick'));
The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function.
-The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.
+The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.
diff --git a/user_guide/database/results.html b/user_guide/database/results.html index 8ad6a1986..0b82752a7 100644 --- a/user_guide/database/results.html +++ b/user_guide/database/results.html @@ -112,7 +112,7 @@ Query ResultsThis function returns the query result as a pure array, or an empty array when no result is produced. Typically you'll use this in a foreach loop, like this:
+This function returns the query result as a pure array, or an empty array when no result is produced. Typically you'll use this in a foreach loop, like this:
$query = $this->db->query("YOUR QUERY");
@@ -126,8 +126,8 @@ Query Results
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:
+ 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:
$query = $this->db->query("YOUR QUERY");
@@ -157,7 +157,7 @@ Query Results
row_array()
- Identical to the above row() function, except it returns an array. Example:
+ Identical to the above row() function, except it returns an array. Example:
$query = $this->db->query("YOUR QUERY");
@@ -209,7 +209,7 @@ echo $query->num_rows();
$query->num_fields()
-The number of FIELDS (columns) returned by the query. Make sure to call the function using your query result object:
+The number of FIELDS (columns) returned by the query. Make sure to call the function using your query result object:
$query = $this->db->query('SELECT * FROM my_table');
echo $query->num_fields();
@@ -218,9 +218,9 @@ echo $query->num_fields();
$query->free_result()
-It frees the memory associated with the result and deletes the result resource ID. Normally PHP frees its memory automatically at the end of script
-execution. However, if you are running a lot of queries in a particular script you might want to free the result after each query result has been
-generated in order to cut down on memory consumptions. Example:
+
It frees the memory associated with the result and deletes the result resource ID. Normally PHP frees its memory automatically at the end of script
+execution. However, if you are running a lot of queries in a particular script you might want to free the result after each query result has been
+generated in order to cut down on memory consumptions. Example:
$query = $this->db->query('SELECT title FROM my_table');
@@ -228,12 +228,12 @@ foreach ($query->result() as $row)
{
echo $row->title;
}
-$query->free_result(); // The $query result object will no longer be available
+$query->free_result(); // The $query result object will no longer be available
$query2 = $this->db->query('SELECT name FROM some_table');
$row = $query2->row();
echo $row->name;
-$query2->free_result(); // The $query2 result object will no longer be available
+$query2->free_result(); // The $query2 result object will no longer be available
diff --git a/user_guide/database/table_data.html b/user_guide/database/table_data.html
index a2aaa99a8..631e3b9d1 100644
--- a/user_guide/database/table_data.html
+++ b/user_guide/database/table_data.html
@@ -65,7 +65,7 @@ Table Data
$this->db->list_tables();
-Returns an array containing the names of all the tables in the database you are currently connected to. Example:
+Returns an array containing the names of all the tables in the database you are currently connected to. Example:
$tables = $this->db->list_tables();
@@ -79,7 +79,7 @@ foreach ($tables as $table)
$this->db->table_exists();
Sometimes it's helpful to know whether a particular table exists before running an operation on it.
-Returns a boolean TRUE/FALSE. Usage example:
+Returns a boolean TRUE/FALSE. Usage example:
if ($this->db->table_exists('table_name'))
@@ -88,7 +88,7 @@ if ($this->db->table_exists('table_name'))
}
-Note: Replace table_name with the name of the table you are looking for.
+Note: Replace table_name with the name of the table you are looking for.
diff --git a/user_guide/database/transactions.html b/user_guide/database/transactions.html
index 74945d434..68d76dff6 100644
--- a/user_guide/database/transactions.html
+++ b/user_guide/database/transactions.html
@@ -61,18 +61,18 @@ Transactions
Transactions
-CodeIgniter'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 than the more common MyISAM. Most other database platforms support transactions natively.
+CodeIgniter'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 than 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
+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.
CodeIgniter's Approach to Transactions
-CodeIgniter utilizes an approach to transactions that is very similar to the process used by the popular database class ADODB. We've chosen that approach
-because it greatly simplifies the process of running transactions. In most cases all that is required are two lines of code.
+CodeIgniter utilizes an approach to transactions that is very similar to the process used by the popular database class ADODB. We've chosen that approach
+because it greatly simplifies the process of running transactions. In most cases all that is required are two lines of code.
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
@@ -98,7 +98,7 @@ of any given query.
Strict Mode
-By default CodeIgniter runs all transactions in Strict Mode. When strict mode is enabled, if you are running multiple groups of
+
By default CodeIgniter runs all transactions in Strict Mode. When strict mode is enabled, if you are running multiple groups of
transactions, if one group fails all groups will be rolled back. If strict mode is disabled, each group is treated independently, meaning
a failure of one group will not affect any others.
@@ -127,7 +127,7 @@ if ($this->db->trans_status() === FALSE)
Enabling Transactions
-Transactions are enabled automatically the moment you use $this->db->trans_start(). If you would like to disable transactions you
+
Transactions are enabled automatically the moment you use $this->db->trans_start(). If you would like to disable transactions you
can do so using $this->db->trans_off():
diff --git a/user_guide/database/utilities.html b/user_guide/database/utilities.html
index c488180a8..ec45f2688 100644
--- a/user_guide/database/utilities.html
+++ b/user_guide/database/utilities.html
@@ -105,7 +105,7 @@ foreach ($dbs as $db)
$this->dbutil->database_exists();
Sometimes it's helpful to know whether a particular database exists.
-Returns a boolean TRUE/FALSE. Usage example:
+Returns a boolean TRUE/FALSE. Usage example:
if ($this->dbutil->database_exists('database_name'))
@@ -114,7 +114,7 @@ if ($this->dbutil->database_exists('database_name'))
}
-Note: Replace database_name with the name of the table you are looking for. This function is case sensitive.
+Note: Replace database_name with the name of the table you are looking for. This function is case sensitive.
@@ -184,7 +184,7 @@ echo $this->dbutil->csv_from_result($query);
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:
+set the delimiter and newline character. By default tabs are used as the delimiter and "\n" is used as a new line. Example:
$delimiter = ",";
@@ -193,14 +193,14 @@ $newline = "\r\n";
echo $this->dbutil->csv_from_result($query, $delimiter, $newline);
-Important: This function will NOT write the CSV file for you. It simply creates the CSV layout.
+
Important: This function will NOT write the CSV file for you. It simply creates the CSV layout.
If you need to write the file use the File Helper.
$this->dbutil->xml_from_result($db_result)
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:
+may contain an optional array of config parameters. Example:
$this->load->dbutil();
@@ -217,18 +217,18 @@ $config = array (
echo $this->dbutil->xml_from_result($query, $config);
-Important: This function will NOT write the XML file for you. It simply creates the XML layout.
+
Important: This function will NOT write the XML file for you. It simply creates the XML layout.
If you need to write the file use the File Helper.
$this->dbutil->backup()
-Permits you to backup your full database or individual tables. The backup data can be compressed in either Zip or Gzip format.
+Permits you to backup your full database or individual tables. The backup data can be compressed in either Zip or Gzip format.
Note: This features is only available for MySQL 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.
Usage Example
@@ -278,7 +278,7 @@ $this->dbutil->backup($prefs);
Options
Description
-tables empty array None An array of tables you want backed up. If left blank all tables will be exported.
+tables empty array None An array of tables you want backed up. If left blank all tables will be exported.
ignore empty array None An array of tables you want the backup routine to ignore.
--
cgit v1.2.3-24-g4f1b