|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
ar_pinp::allow('ar_connect_db'); |
|
4
|
|
|
ar_pinp::allow('ar_connect_dbClient'); |
|
5
|
|
|
|
|
6
|
|
|
class ar_connect_db extends arBase { |
|
7
|
|
|
|
|
8
|
|
|
public static function connect( $dsn, $username='', $password='', $driver_options=array() ) { |
|
9
|
|
|
// deprecated |
|
10
|
|
|
return self::client( $dsn, $username, $password, $driver_options ); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
public static function client( $dsn, $username='', $password='', $driverOptions = array() ) { |
|
14
|
|
|
try { |
|
15
|
|
|
return new ar_connect_dbClient( new PDO($dsn, $username, $password, $driverOptions) ); |
|
16
|
|
|
} catch( Exception $e ) { |
|
17
|
|
|
return ar::error( $e->getMessage(), $e->getCode() ); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
// FIXME: define an interface |
|
24
|
|
|
|
|
25
|
|
|
class ar_connect_dbClient extends arWrapper implements Iterator { |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( $wrapped ) { |
|
28
|
|
|
parent::__construct($wrapped); |
|
29
|
|
|
$this->__class = 'ar_connect_dbClient'; |
|
30
|
|
|
if ($this->wrapped instanceof PDOStatement) { |
|
31
|
|
|
$this->row = $this->wrapped->fetch(); |
|
|
|
|
|
|
32
|
|
|
if (!$this->row) { |
|
|
|
|
|
|
33
|
|
|
$this->row = null; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
$this->cursor = 0; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function current() { |
|
40
|
|
|
return $this->row; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function key() { |
|
44
|
|
|
return $this->cursor; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
public function next() { |
|
48
|
|
|
if ($this->wrapped instanceof PDOStatement) { |
|
49
|
|
|
$this->row = $this->wrapped->fetch(); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
if (!$this->row) { |
|
|
|
|
|
|
52
|
|
|
$this->row = null; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
$this->cursor++; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
public function rewind() { |
|
58
|
|
|
if ($this->wrapped instanceof PDOStatement) { |
|
59
|
|
|
$this->wrapped->execute(); |
|
60
|
|
|
$this->row = $this->wrapped->fetch(); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
if (!$this->row) { |
|
|
|
|
|
|
63
|
|
|
$this->row = null; |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
$this->cursor = 0; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function valid() { |
|
69
|
|
|
// note: somehow isset() returns false here, so use is_array instead. |
|
70
|
|
|
return is_array($this->row); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.