Skip to content

Commit

Permalink
update database/, code-block(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
totoprayogo1916 authored and paulbalandan committed Jan 25, 2021
1 parent 4873922 commit 885a12a
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 156 deletions.
2 changes: 1 addition & 1 deletion user_guide_src/source/database/call_function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $db->callFunction();

This function enables you to call PHP database functions that are not
natively included in CodeIgniter, in a platform-independent manner. For
example, let's say you want to call the mysql_get_client_info()
example, let's say you want to call the ``mysql_get_client_info()``
function, which is **not** natively supported by CodeIgniter. You could
do so like this::

Expand Down
6 changes: 3 additions & 3 deletions user_guide_src/source/database/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ driver's underlying native PHP extension, like this::
will try to build it with the rest of the provided settings.

You can also set a Data Source Name in universal manner (URL like). In that case DSNs must have this prototype::

$default['DSN'] = 'DBDriver://username:password@hostname:port/database';

To override default config values when connecting with a universal version of the DSN string,
To override default config values when connecting with a universal version of the DSN string,
add the config variables as a query string::

// MySQLi
Expand Down Expand Up @@ -184,7 +184,7 @@ Explanation of Values:
**username** The username used to connect to the database.
**password** The password used to connect to the database.
**database** The name of the database you want to connect to.
**DBDriver** The database type. eg: MySQLi, Postgre, etc. The case must match the driver name
**DBDriver** The database type. e.g.,: MySQLi, Postgre, etc. The case must match the driver name
**DBPrefix** An optional table prefix which will added to the table name when running
:doc:`Query Builder <query_builder>` queries. This permits multiple CodeIgniter
installations to share one database.
Expand Down
9 changes: 4 additions & 5 deletions user_guide_src/source/database/connecting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ and is provided for your convenience::
Available Parameters
--------------------

#. The database group name, a string that must match the config class' property name. Default value is $config->defaultGroup.
#. The database group name, a string that must match the config class' property name. Default value is ``$config->defaultGroup``.
#. TRUE/FALSE (boolean). Whether to return the shared connection (see
Connecting to Multiple Databases below).

Expand Down Expand Up @@ -63,8 +63,7 @@ group names you are connecting to.
.. note:: You don't need to create separate database configurations if you
only need to use a different database on the same connection. You
can switch to a different database when you need to, like this:

$db->setDatabase($database2_name);
``$db->setDatabase($database2_name);``

Connecting with Custom Settings
===============================
Expand Down Expand Up @@ -100,11 +99,11 @@ Reconnecting / Keeping the Connection Alive

If the database server's idle timeout is exceeded while you're doing
some heavy PHP lifting (processing an image, for instance), you should
consider pinging the server by using the reconnect() method before
consider pinging the server by using the ``reconnect()`` method before
sending further queries, which can gracefully keep the connection alive
or re-establish it.

.. important:: If you are using MySQLi database driver, the reconnect() method
.. important:: If you are using MySQLi database driver, the ``reconnect()`` method
does not ping the server but it closes the connection then connects again.

::
Expand Down
20 changes: 11 additions & 9 deletions user_guide_src/source/database/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Standard Query With Multiple Results (Object Version)

echo 'Total Results: ' . count($results);

The above getResult() function returns an array of **objects**. Example:
$row->title
| The above ``getResult()`` function returns an array of **objects**.
| Example: ``$row->title``
Standard Query With Multiple Results (Array Version)
====================================================
Expand All @@ -54,8 +54,9 @@ Standard Query With Multiple Results (Array Version)
echo $row['email'];
}

The above getResultArray() function returns an array of standard array
indexes. Example: $row['title']
| The above ``getResultArray()`` function returns an array of standard array
indexes.
| Example: ``$row['title']``
Standard Query With Single Result
=================================
Expand All @@ -66,7 +67,7 @@ Standard Query With Single Result
$row = $query->getRow();
echo $row->name;

The above getRow() function returns an **object**. Example: $row->name
The above ``getRow()`` function returns an **object**. Example: ``$row->name``

Standard Query With Single Result (Array version)
=================================================
Expand All @@ -77,8 +78,8 @@ Standard Query With Single Result (Array version)
$row = $query->getRowArray();
echo $row['name'];

The above getRowArray() function returns an **array**. Example:
$row['name']
The above ``getRowArray()`` function returns an **array**. Example:
``$row['name']``.

Standard Insert
===============
Expand All @@ -102,7 +103,7 @@ means of retrieving data::
echo $row->title;
}

The above get() function retrieves all the results from the supplied
The above ``get()`` function retrieves all the results from the supplied
table. The :doc:`Query Builder <query_builder>` class contains a full
complement of functions for working with data.

Expand All @@ -117,5 +118,6 @@ Query Builder Insert
'date' => $date
];

$db->table('mytable')->insert($data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
$db->table('mytable')->insert($data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')

5 changes: 2 additions & 3 deletions user_guide_src/source/database/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ List the Fields in a Table
Returns an array containing the field names. This query can be called
two ways:

1. You can supply the table name and call it from the $db->
object::
1. You can supply the table name and call it from the ``$db->object``::

$fields = $db->getFieldNames('table_name');

Expand Down Expand Up @@ -146,7 +145,7 @@ Usage example::
{
echo $key->name;
echo $key->type;
echo $key->fields; // array of field names
echo $key->fields; // array of field names
}

The key types may be unique to the database you are using.
Expand Down
38 changes: 19 additions & 19 deletions user_guide_src/source/database/queries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To submit a query, use the **query** function::

$db->query('YOUR QUERY HERE');

The query() function returns a database result **object** when "read"
The ``query()`` function returns a database result **object** when "read"
type queries are run which you can use to :doc:`show your
results <results>`. When "write" type queries are run it simply
returns TRUE or FALSE depending on success or failure. When retrieving
Expand All @@ -30,12 +30,12 @@ Simplified Queries
==================

The **simpleQuery** method is a simplified version of the
$db->query() method. It DOES
``$db->query()`` method. 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 returns whatever the database drivers' "execute" function returns.
It returns whatever the database drivers "execute" function returns.
That typically is TRUE/FALSE on success or failure for write type queries
such as INSERT, DELETE or UPDATE statements (which is what it really
should be used for) and a resource/object on success for queries with
Expand Down Expand Up @@ -111,14 +111,14 @@ this:
single quotes around the data so you don't have to:
::

$sql = "INSERT INTO table (title) VALUES(".$db->escape($title).")";
$sql = "INSERT INTO table (title) VALUES(" . $db->escape($title) . ")";

#. **$db->escapeString()** This function escapes the data passed to
it, regardless of type. Most of the time you'll use the above
function rather than this one. Use the function like this:
::

$sql = "INSERT INTO table (title) VALUES('".$db->escapeString($title)."')";
$sql = "INSERT INTO table (title) VALUES('" . $db->escapeString($title) . "')";

#. **$db->escapeLikeString()** This method should be used when
strings are to be used in LIKE conditions so that LIKE wildcards
Expand All @@ -128,7 +128,7 @@ this:

$search = '20% raise';
$sql = "SELECT id FROM table WHERE column LIKE '%" .
$db->escapeLikeString($search)."%' ESCAPE '!'";
$db->escapeLikeString($search) . "%' ESCAPE '!'";

.. important:: The ``escapeLikeString()`` method uses '!' (exclamation mark)
to escape special characters for *LIKE* conditions. Because this
Expand Down Expand Up @@ -184,7 +184,7 @@ Handling Errors

**$db->error();**

If you need to get the last error that has occurred, the error() method
If you need to get the last error that has occurred, the ``error()`` method
will return an array containing its code and message. Here's a quick
example::

Expand Down Expand Up @@ -217,11 +217,11 @@ as placeholders. This returns a PreparedQuery object::
$pQuery = $db->prepare(function($db)
{
return $db->table('user')
->insert([
'name' => 'x',
'email' => 'y',
'country' => 'US'
]);
->insert([
'name' => 'x',
'email' => 'y',
'country' => 'US'
]);
});

If you don't want to use the Query Builder you can create the Query object manually using question marks for
Expand Down Expand Up @@ -260,11 +260,11 @@ query::
$pQuery = $db->prepare(function($db)
{
return $db->table('user')
->insert([
'name' => 'x',
'email' => 'y',
'country' => 'US'
]);
->insert([
'name' => 'x',
'email' => 'y',
'country' => 'US'
]);
});

// Collect the Data
Expand Down Expand Up @@ -295,7 +295,7 @@ This returns the prepared query as a string.

**hasError()**

Returns boolean true/false if the last execute() call created any errors.
Returns boolean true/false if the last ``execute()`` call created any errors.

**getErrorCode()**
**getErrorMessage()**
Expand Down Expand Up @@ -357,7 +357,7 @@ will return true::

**isWriteType()**

Returns true if the query was determined to be a write-type query (i.e.
Returns true if the query was determined to be a write-type query (i.e.,
INSERT, UPDATE, DELETE, etc)::

if ($query->isWriteType())
Expand Down
Loading

0 comments on commit 885a12a

Please sign in to comment.