Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
mysqlconnection.php
1
<?php
2
namespace
Bitrix\Main\DB
;
3
4
use
Bitrix\Main\Diag
;
5
6
class
MysqlConnection
extends
MysqlCommonConnection
7
{
8
/**********************************************************
9
* SqlHelper
10
**********************************************************/
11
15
protected
function
createSqlHelper
()
16
{
17
return
new
MysqlSqlHelper
($this);
18
}
19
20
/***********************************************************
21
* Connection and disconnection
22
***********************************************************/
23
32
protected
function
connectInternal
()
33
{
34
if
($this->
isConnected
)
35
{
36
return
;
37
}
38
39
if
(($this->options & self::PERSISTENT) != 0)
40
{
41
$connection = mysql_pconnect($this->host, $this->login, $this->password);
42
}
43
else
44
{
45
$connection = mysql_connect($this->host, $this->login, $this->password,
true
);
46
}
47
48
if
(!$connection)
49
{
50
throw
new
ConnectionException
(
'Mysql connect error ['
.$this->host.
', '
.gethostbyname($this->host).
']'
, mysql_error());
51
}
52
53
if
($this->database !==
null
)
54
{
55
if
(!mysql_select_db($this->database, $connection))
56
{
57
throw
new
ConnectionException
(
'Mysql select db error ['
.$this->database.
']'
, mysql_error($connection));
58
}
59
}
60
61
$this->resource = $connection;
62
$this->
isConnected
=
true
;
63
64
$this->afterConnected();
65
}
66
73
public
function
disconnectInternal
()
74
{
75
if
(!$this->
isConnected
)
76
return
;
77
78
mysql_close($this->resource);
79
80
$this->
isConnected
=
false
;
81
}
82
83
/*********************************************************
84
* Query
85
*********************************************************/
86
90
protected
function
queryInternal
($sql, array $binds =
null
, \
Bitrix
\Main\Diag\
SqlTrackerQuery
$trackerQuery =
null
)
91
{
92
$this->
connectInternal
();
93
94
if
($trackerQuery !=
null
)
95
$trackerQuery->startQuery($sql, $binds);
96
97
$result = mysql_query($sql, $this->resource);
98
99
if
($trackerQuery !=
null
)
100
$trackerQuery->finishQuery();
101
102
$this->lastQueryResult = $result;
103
104
if
(!$result)
105
throw
new
SqlQueryException
(
'Mysql query error'
, mysql_error($this->resource), $sql);
106
107
return
$result;
108
}
109
113
protected
function
createResult
($result, \
Bitrix
\Main\Diag\
SqlTrackerQuery
$trackerQuery =
null
)
114
{
115
return
new
MysqlResult
($result, $this, $trackerQuery);
116
}
117
121
public
function
getInsertedId
()
122
{
123
$this->
connectInternal
();
124
return
mysql_insert_id($this->resource);
125
}
126
130
public
function
getAffectedRowsCount
()
131
{
132
return
mysql_affected_rows($this->
getResource
());
133
}
134
135
/*********************************************************
136
* Type, version, cache, etc.
137
*********************************************************/
138
142
public
function
getVersion
()
143
{
144
if
($this->version ==
null
)
145
{
146
$version = $this->queryScalar(
"SELECT VERSION()"
);
147
if
($version !=
null
)
148
{
149
$version = trim($version);
150
preg_match(
"#[0-9]+\\.[0-9]+\\.[0-9]+#"
, $version, $ar);
151
$this->version = $ar[0];
152
}
153
}
154
155
return
array($this->version,
null
);
156
}
157
161
protected
function
getErrorMessage
()
162
{
163
return
sprintf(
"[%s] %s"
, mysql_errno($this->resource), mysql_error($this->resource));
164
}
165
172
public
function
selectDatabase
($database)
173
{
174
return
mysql_select_db($database, $this->resource);
175
}
176
}
Bitrix\Main\DB\ConnectionException
Definition
connectionexception.php:11
Bitrix\Main\DB\MysqlCommonConnection
Definition
mysqlcommonconnection.php:9
Bitrix\Main\DB\MysqlConnection
Definition
mysqlconnection.php:7
Bitrix\Main\DB\MysqlConnection\createSqlHelper
createSqlHelper()
Definition
mysqlconnection.php:15
Bitrix\Main\DB\MysqlConnection\connectInternal
connectInternal()
Definition
mysqlconnection.php:32
Bitrix\Main\DB\MysqlConnection\getErrorMessage
getErrorMessage()
Definition
mysqlconnection.php:161
Bitrix\Main\DB\MysqlConnection\disconnectInternal
disconnectInternal()
Definition
mysqlconnection.php:73
Bitrix\Main\DB\MysqlConnection\createResult
createResult($result, \Bitrix\Main\Diag\SqlTrackerQuery $trackerQuery=null)
Definition
mysqlconnection.php:113
Bitrix\Main\DB\MysqlConnection\queryInternal
queryInternal($sql, array $binds=null, \Bitrix\Main\Diag\SqlTrackerQuery $trackerQuery=null)
Definition
mysqlconnection.php:90
Bitrix\Main\DB\MysqlConnection\getInsertedId
getInsertedId()
Definition
mysqlconnection.php:121
Bitrix\Main\DB\MysqlConnection\getAffectedRowsCount
getAffectedRowsCount()
Definition
mysqlconnection.php:130
Bitrix\Main\DB\MysqlConnection\getVersion
getVersion()
Definition
mysqlconnection.php:142
Bitrix\Main\DB\MysqlConnection\selectDatabase
selectDatabase($database)
Definition
mysqlconnection.php:172
Bitrix\Main\DB\MysqlResult
Definition
mysqlresult.php:5
Bitrix\Main\DB\MysqlSqlHelper
Definition
mysqlsqlhelper.php:7
Bitrix\Main\DB\SqlQueryException
Definition
sqlexception.php:24
Bitrix\Main\Data\Connection\getResource
getResource()
Definition
connection.php:51
Bitrix\Main\Data\Connection\isConnected
isConnected()
Definition
connection.php:62
Bitrix\Main\Diag\SqlTrackerQuery
Definition
sqltrackerquery.php:5
Bitrix\Main\DB
Definition
arrayresult.php:2
Bitrix\Main\Diag
Definition
cachetracker.php:2
Bitrix
modules
main
lib
db
mysqlconnection.php
Создано системой
1.10.0