Skip to content

Commit 38b80f3

Browse files
committed
Fix connect error
1 parent 2281591 commit 38b80f3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Hhxsv5\LaravelS\Illuminate\Database;
4+
5+
class ConnectionException extends \Exception
6+
{
7+
8+
}

src/Illuminate/Database/SwoolePDO.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,28 @@ public function __construct()
1515
$this->sm = new SwooleMySQL();
1616
}
1717

18+
/**
19+
* @param array $serverInfo
20+
* @throws ConnectionException
21+
*/
1822
public function connect(array $serverInfo)
1923
{
2024
$this->sm->connect($serverInfo);
25+
26+
if ($this->sm->connected === false) {
27+
throw new ConnectionException(
28+
'Cannot connect to the database: ' . $this->sm->connect_error,
29+
$this->sm->connect_errno
30+
);
31+
}
32+
2133
}
2234

2335
public function prepare($statement, $options = null)
2436
{
2537
$swStatement = $this->sm->prepare($statement);
2638
if ($swStatement === false) {
27-
throw new QueryException($statement, [], new \Exception($this->sm->error, $this->sm->errno));
39+
throw new QueryException($statement, [], new StatementException($this->sm->error, $this->sm->errno));
2840
}
2941
return new SwoolePDOStatement($swStatement);
3042
}

0 commit comments

Comments
 (0)