Completed
Pull Request — development (#3101)
by John
09:34
created

Database.subs.php ➔ db_extend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file has all the main functions in it that set up the database connection
5
 * and initializes the appropriate adapters.
6
 *
7
 * @name      ElkArte Forum
8
 * @copyright ElkArte Forum contributors
9
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
10
 *
11
 * @version 2.0 dev
12
 *
13
 */
14
15
/**
16
 * Initialize database classes and connection.
17
 *
18
 * @param string $db_server
19
 * @param string $db_name
20
 * @param string $db_user
21
 * @param string $db_passwd
22
 * @param mixed[] $db_options
23
 * @param string $db_type
24
 *
25
 * @return resource
26
 */
27
function elk_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_options = array(), $db_type = 'mysql')
28
{
29
	require_once(SOURCEDIR . '/database/Db.php');
30
	require_once(SOURCEDIR . '/database/Db-abstract.class.php');
31
	require_once(SOURCEDIR . '/database/Db-' . $db_type . '.class.php');
32
33
	return call_user_func(array('Database_' . DB_TYPE, 'initiate'), $db_server, $db_name, $db_user, $db_passwd, $db_options);
34
}
35
36
/**
37
 * Retrieve existing instance of the active database class.
38
 *
39
 * @return Database
40
 */
41
function database()
42
{
43 62
	return call_user_func(array('Database_' . DB_TYPE, 'db'));
44
}
45
46
/**
47
 * This function retrieves an existing instance of DbTable
48
 * and returns it.
49
 *
50
 * @param object|null $db - A database object (e.g. Database_MySQL or Database_PostgreSQL)
51
 * @return DbTable
52
 */
53
function db_table($db = null)
54
{
55
	if ($db === null)
56
		$db = database();
57
58
	require_once(SOURCEDIR . '/database/DbTable.class.php');
59
	require_once(SOURCEDIR . '/database/DbTable-' . strtolower(DB_TYPE) . '.php');
60
61
	return call_user_func(array('DbTable_' . DB_TYPE, 'db_table'), $db);
62
}
63
64
/**
65
 * This function returns an instance of DbSearch,
66
 * specifically designed for database utilities related to search.
67
 *
68
 * @return DbSearch
69
 *
70
 */
71
function db_search()
72
{
73 11
	require_once(SOURCEDIR . '/database/DbSearch.php');
74 11
	require_once(SOURCEDIR . '/database/DbSearch-' . strtolower(DB_TYPE) . '.php');
75
76 11
	return call_user_func(array('DbSearch_' . DB_TYPE, 'db_search'));
77
}
78