Skip to content

Commit d182d63

Browse files
committed
setDateTime method implemented for mysql parameters
1 parent e62918e commit d182d63

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

berry/mysql/MySQLCommandParameters.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ public function setBlob(int $paramIndex, $value, $length = NULL): void
6565
$this->Add($paramIndex, $value, "b", $length);
6666
}
6767

68+
/**
69+
* Adds or sets the current time measured in the number of seconds
70+
* since the Unix Epoch (January 1 1970 00:00:00 GMT).
71+
* This method should be used with DateTime MySql variables.
72+
* @param int $paramIndex
73+
* @param int $secondsSinceUnixEpoch is the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
74+
* @param type $length
75+
* @return void
76+
*/
77+
public function setDateTime(int $paramIndex, int $secondsSinceUnixEpoch): void
78+
{
79+
$datetime = date("Y-m-d H:i:s", $secondsSinceUnixEpoch);
80+
$this->Add($paramIndex, $datetime, "s", NULL);
81+
}
82+
6883
/**
6984
* Remove all parameters
7085
*/
@@ -77,7 +92,6 @@ public function getParameters(): array
7792
{
7893
return $this->fParameters;
7994
}
80-
8195
}
8296

8397
?>

berry/mysql/MySQLConnection.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class MySQLConnection
44
{
55

66
private mysqli $fLink; // The mysqli link with the selected MySQL database
7-
private bool $fConnectionIsOpen = false;
87

98
/**
109
* Constructs a new MySQLConnection
@@ -20,15 +19,13 @@ public function __construct(string $serverIP, string $database, string $user, st
2019

2120
if ($this->fLink->connect_errno)
2221
{
23-
throw new Exception("Failed to connect to MySQL:" . $this->fLink->connect_error);
22+
throw new Exception("Failed to connect to MySQL: " . $this->fLink->connect_error);
2423
}
2524

2625
if ($charset != "")
2726
{
2827
$this->fLink->set_charset($charset);
2928
}
30-
31-
$this->fConnectionIsOpen = true;
3229
}
3330

3431
/**
@@ -47,12 +44,7 @@ public function EscapeString(string $string): string
4744
*/
4845
public function Close(): void
4946
{
50-
// Check if connection (fLink) is open before closing it
51-
if ($this->fConnectionIsOpen)
52-
{
53-
$this->fLink->close();
54-
$this->fConnectionIsOpen = false;
55-
}
47+
$this->fLink->close();
5648
}
5749

5850
/**
@@ -63,6 +55,7 @@ public function getLink(): mysqli
6355
{
6456
return $this->fLink;
6557
}
58+
6659
}
6760

6861
?>

0 commit comments

Comments
 (0)