|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Soluble Components (http://belgattitude.github.io/solublecomponents) |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/belgattitude/solublecomponents for the canonical source repository |
|
6
|
|
|
* @copyright Copyright (c) 2013-2014 Sébastien Vanvelthem |
|
7
|
|
|
* @license https://github.com/belgattitude/solublecomponents/blob/master/LICENSE.txt MIT License |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace Soluble\Db\Compat; |
|
10
|
|
|
|
|
11
|
|
|
use Zend\Db\Adapter\Adapter; |
|
12
|
|
|
|
|
13
|
|
|
class Adodb |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Return a Zend\Db\Adapter\Adapter connection from an existing ADODb connection |
|
17
|
|
|
* |
|
18
|
|
|
* @throws Exception\UnsupportedDriverException |
|
19
|
|
|
* @throws Exception\AdoNotConnectedException when connection is not initialized |
|
20
|
|
|
* |
|
21
|
|
|
* @param \ADOConnection $adoConnection |
|
22
|
|
|
* @return Adapter |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function getAdapter(\ADOConnection $adoConnection) |
|
25
|
|
|
{ |
|
26
|
|
|
$adoConnectionDriver = strtolower(get_class($adoConnection)); |
|
27
|
|
|
switch ($adoConnectionDriver) { |
|
28
|
|
|
//case 'adodb_mysqlt': |
|
29
|
|
|
case 'adodb_mysqli': |
|
30
|
|
|
$connectionId = self::getADOConnectionId($adoConnection); |
|
31
|
|
|
$adapter = Mysqli::getAdapter($connectionId); |
|
|
|
|
|
|
32
|
|
|
break; |
|
33
|
|
|
case 'adodb_pdo': |
|
34
|
|
|
case 'adodb_pdo_mysql': |
|
35
|
|
|
$connectionId = self::getADOConnectionId($adoConnection); |
|
36
|
|
|
$adapter = PDO::getAdapter($connectionId); |
|
|
|
|
|
|
37
|
|
|
break; |
|
38
|
|
|
default: |
|
39
|
|
|
throw new Exception\UnsupportedDriverException(__METHOD__ . ". Driver '$adoConnectionDriver' not supported"); |
|
40
|
|
|
} |
|
41
|
|
|
return $adapter; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Return internal adodb internal connection id |
|
46
|
|
|
* @throws Exception\AdoNotConnectedException when connection is not initialized |
|
47
|
|
|
* @param \ADOConnection $adoConnection |
|
48
|
|
|
* @return \MySQLI|\PDO |
|
49
|
|
|
*/ |
|
50
|
|
|
protected static function getADOConnectionId(\ADOConnection $adoConnection) |
|
51
|
|
|
{ |
|
52
|
|
|
$connectionId = $adoConnection->_connectionID; |
|
53
|
|
|
if (!$connectionId) { |
|
54
|
|
|
throw new Exception\AdoNotConnectedException(__METHOD__ . ". Error: Invalid usage, adodb connection must be connected before use (see connect(), pconnect()"); |
|
55
|
|
|
} |
|
56
|
|
|
return $connectionId; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.