Completed
Pull Request — master (#3237)
by Emanuele
14:50
created

Database.subs.php ➔ db_table()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 2
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 1.1
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 string $db_prefix
23
 * @param mixed[] $db_options
24
 * @param string $db_type
25
 * @return resource
26
 */
27
function elk_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $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(array('Database_' . DB_TYPE, 'initiate'), array($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options));
34
}
35
36
/**
37
 * Extend the database functionality.
38
 */
39
function db_extend()
40
{
41
	// @todo this can be removed.
42
}
43
44
/**
45
 * Retrieve existing instance of the active database class.
46
 *
47
 * @return Database
48
 */
49
function database()
50
{
51 58
	return call_user_func(array('Database_' . DB_TYPE, 'db'));
52
}
53
54
/**
55
 * This function retrieves an existing instance of DbTable
56
 * and returns it.
57
 *
58
 * @param object|null $db - A database object (e.g. Database_MySQL or Database_PostgreSQL)
59
 * @return DbTable
60
 */
61
function db_table($db = null)
62
{
63 1
	if ($db === null)
64 1
		$db = database();
65
66 1
	require_once(SOURCEDIR . '/database/DbTable.class.php');
67 1
	require_once(SOURCEDIR . '/database/DbTable-' . strtolower(DB_TYPE) . '.php');
68
69 1
	return call_user_func(array('DbTable_' . DB_TYPE, 'db_table'), $db);
70
}
71
72
/**
73
 * This function returns an instance of DbSearch,
74
 * specifically designed for database utilities related to search.
75
 *
76
 * @return DbSearch
77
 *
78
 */
79
function db_search()
80
{
81 11
	require_once(SOURCEDIR . '/database/DbSearch.php');
82 11
	require_once(SOURCEDIR . '/database/DbSearch-' . strtolower(DB_TYPE) . '.php');
83
84 11
	return call_user_func(array('DbSearch_' . DB_TYPE, 'db_search'));
85
}
86