Skip to content

Commit ebef99e

Browse files
committed
getDateTime() method implemented at MySQLDataReader
1 parent d182d63 commit ebef99e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

berry/mysql/MySQLConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(string $serverIP, string $database, string $user, st
1919

2020
if ($this->fLink->connect_errno)
2121
{
22-
throw new Exception("Failed to connect to MySQL: " . $this->fLink->connect_error);
22+
throw new Exception("Failed to connect to MySQL: (" . $this->fLink->connect_errno . ") " . $this->fLink->connect_error);
2323
}
2424

2525
if ($charset != "")

berry/mysql/MySQLDataReader.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,29 @@ public function Close()
7575
}
7676

7777
/**
78-
* Return a readed value
78+
* Return a read value
7979
* @param type $index
8080
* @return type
8181
*/
82-
public function getValue($index)
82+
public function getValue(int $index)
8383
{
8484
return $this->fReadValues[$index];
8585
}
8686

87+
/**
88+
* Returns a read MySQL datetime value into a PHP DateTime Object.
89+
* The returned DateTime object's Time-Zone will be convert to the given TimeZone.
90+
* Notice: MySql datetime object holds DateTime into UTC timezone.
91+
* @param int $index
92+
* @param DateTimeZone $timeZone
93+
* @return DateTime
94+
*/
95+
public function getDateTime(int $index, DateTimeZone $timeZone): DateTime
96+
{
97+
$dt = new DateTime($this->fReadValues[$index]);
98+
$dt->setTimezone($timeZone);
99+
return $dt;
100+
}
87101
}
88102

89103
?>

0 commit comments

Comments
 (0)