1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mysqliconnection.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\DB;
4
5use Bitrix\Main\Diag;
6
13{
15 {
16 parent::__construct($configuration);
17
18 $this->configureReportLevel();
19 }
20
21 /**********************************************************
22 * SqlHelper
23 **********************************************************/
24
25 protected function createSqlHelper()
26 {
27 return new MysqliSqlHelper($this);
28 }
29
30 /***********************************************************
31 * Connection and disconnection
32 ***********************************************************/
33
42 protected function connectInternal()
43 {
44 if ($this->isConnected)
45 {
46 return;
47 }
48
50 $port = 0;
51 if (($pos = strpos($host, ":")) !== false)
52 {
53 $port = intval(substr($host, $pos + 1));
54 $host = substr($host, 0, $pos);
55 }
56 if ($this->isPersistent())
57 {
58 $host = "p:" . $host;
59 }
60
61 $connection = \mysqli_init();
62 if (!$connection)
63 {
64 throw new ConnectionException('Mysql init failed');
65 }
66
67 if (!empty($this->initCommand))
68 {
69 if (!$connection->options(MYSQLI_INIT_COMMAND, $this->initCommand))
70 {
71 throw new ConnectionException('Setting mysql init command failed');
72 }
73 }
74
75 if ($port > 0)
76 {
77 $success = $connection->real_connect($host, $this->login, $this->password, $this->database, $port);
78 }
79 else
80 {
81 $success = $connection->real_connect($host, $this->login, $this->password, $this->database);
82 }
83
84 if (!$success)
85 {
86 throw new ConnectionException(
87 'Mysql connect error [' . $this->host . ']',
88 "({$connection->connect_errno}) {$connection->connect_error}"
89 );
90 }
91
92 $this->resource = $connection;
93 $this->isConnected = true;
94
95 if (isset($this->configuration['charset']))
96 {
97 $connection->set_charset($this->configuration['charset']);
98 }
99
100 // nosql memcached driver
101 if (isset($this->configuration['memcache']))
102 {
103 if (function_exists('mysqlnd_memcache_set'))
104 {
105 $memcached = \Bitrix\Main\Application::getInstance()->getConnectionPool()->getConnection($this->configuration['memcache']);
106 mysqlnd_memcache_set($this->resource, $memcached->getResource());
107 }
108 }
109
110 $this->afterConnected();
111 }
112
119 protected function disconnectInternal()
120 {
121 if ($this->isConnected)
122 {
123 $this->isConnected = false;
124 $this->resource->close();
125 }
126 }
127
128 /*********************************************************
129 * Query
130 *********************************************************/
131
135 protected function queryInternal($sql, array $binds = null, Diag\SqlTrackerQuery $trackerQuery = null)
136 {
137 $this->connectInternal();
138
139 $trackerQuery?->startQuery($sql, $binds);
140
141 $result = $this->resource->query($sql);
142
143 $trackerQuery?->finishQuery();
144
145 $this->lastQueryResult = $result;
146
147 if (!$result)
148 {
149 throw $this->createQueryException($this->getErrorCode(), $this->getErrorMessage(), $sql);
150 }
151
152 return $result;
153 }
154
158 protected function createResult($result, Diag\SqlTrackerQuery $trackerQuery = null)
159 {
160 return new MysqliResult($result, $this, $trackerQuery);
161 }
162
166 public function getInsertedId()
167 {
168 return $this->getResource()->insert_id;
169 }
170
174 public function getAffectedRowsCount()
175 {
176 return $this->getResource()->affected_rows;
177 }
178
179 /*********************************************************
180 * Type, version, cache, etc.
181 *********************************************************/
182
186 public function getVersion()
187 {
188 if ($this->version == null)
189 {
190 $version = trim($this->getResource()->server_info);
191
192 preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+#", $version, $ar);
193 $this->version = $ar[0];
194 }
195
196 return [$this->version, null];
197 }
198
202 public function getErrorMessage()
203 {
204 return "({$this->getErrorCode()}) {$this->resource->error}";
205 }
206
210 public function getErrorCode()
211 {
212 return $this->resource->errno;
213 }
214
221 public function selectDatabase($database)
222 {
223 return $this->resource->select_db($database);
224 }
225
226 protected function configureReportLevel(): void
227 {
228 // back to default before PHP 8.1
229 mysqli_report(MYSQLI_REPORT_OFF);
230 }
231}
$connection
Определения actionsdefinitions.php:38
xml version
Определения yandex.php:67
static getInstance()
Определения application.php:98
createQueryException($code=0, $databaseMessage='', $query='')
Определения mysqlcommonconnection.php:409
createResult($result, Diag\SqlTrackerQuery $trackerQuery=null)
Определения mysqliconnection.php:158
queryInternal($sql, array $binds=null, Diag\SqlTrackerQuery $trackerQuery=null)
Определения mysqliconnection.php:135
selectDatabase($database)
Определения mysqliconnection.php:221
__construct(array $configuration)
Определения mysqliconnection.php:14
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$success
Определения mail_entry.php:69
Определения cachetracker.php:2
$host
Определения mysql_to_pgsql.php:32
$ar
Определения options.php:199