6 Commits
1.0 ... 2.0

Author SHA1 Message Date
User
2e384e2071 20231010#4 2023-10-10 17:18:44 +03:00
User
368ccfa44b 20231010#3 2023-10-10 16:16:21 +03:00
User
f0f862d979 20231010#2 2023-10-10 15:02:59 +03:00
User
c43f3a4768 20231010#1 2023-10-10 14:39:27 +03:00
User
19305af62f 20230926#3 2023-09-26 21:24:37 +03:00
User
23485cd0e3 20230926#2 2023-09-26 20:54:08 +03:00
5 changed files with 17 additions and 11 deletions

View File

@@ -7,15 +7,15 @@ DB component for **Rmphp**
Stable version Stable version
```bash ```bash
composer require rmphp/kernel composer require rmphp/storage
``` ```
```bash ```bash
composer require rmphp/kernel:"^1.0" composer require rmphp/storage:"^2.0"
``` ```
Dev version contains the latest changes Dev version contains the latest changes
```bash ```bash
composer require rmphp/kernel:"1.0.x-dev" composer require rmphp/storage:"2.x-dev"
``` ```

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage\Exception; namespace Rmphp\Storage\Mysql\Exception;
class MysqlException extends \Exception { class MysqlException extends \Exception {

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage; namespace Rmphp\Storage\Mysql;
use Exception; use Exception;
use Mysqli; use Mysqli;
@@ -107,10 +107,12 @@ class MysqlStorage implements MysqlStorageInterface {
} }
/** @inheritDoc */ /** @inheritDoc */
public function read(string $sql, int $ln = 0, int $numPage = 1) : bool|MysqlStorageData { public function read(string $sql, int $ln=0, int $numPage=1, int $count=0): bool|MysqlStorageData {
if ($ln > 1) { if ($ln > 1) {
$cnts = $this->query($sql)->num_rows; $cnts = (!empty($count)) ? $count : $this->query($sql)->num_rows;
} }
// часть строки запроса с лимит // часть строки запроса с лимит
switch (true){ switch (true){
case ($ln > 1 || $numPage > 1) : $limit = " limit ".(($numPage * $ln) - $ln).", ".$ln; break; case ($ln > 1 || $numPage > 1) : $limit = " limit ".(($numPage * $ln) - $ln).", ".$ln; break;
@@ -123,9 +125,12 @@ class MysqlStorage implements MysqlStorageInterface {
$data = new MysqlStorageData($result); $data = new MysqlStorageData($result);
$data->count = $cnts ?? 0; $data->count = $cnts ?? 0;
$data->hex = md5($sql);
return $data; return $data;
} }
/** @inheritDoc */ /** @inheritDoc */
public function chktbl(string $tbl) : bool { public function chktbl(string $tbl) : bool {
$result = $this->mysqli->query("SHOW TABLES LIKE '".$this->escapeStr($tbl)."'"); $result = $this->mysqli->query("SHOW TABLES LIKE '".$this->escapeStr($tbl)."'");

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage; namespace Rmphp\Storage\Mysql;
class MysqlStorageData { class MysqlStorageData {
@@ -8,6 +8,7 @@ class MysqlStorageData {
private ?\mysqli_result $result; private ?\mysqli_result $result;
private array $arrayData = []; private array $arrayData = [];
public int $count; public int $count;
public string $hex = "";
/** /**
* MysqlDataObject constructor. * MysqlDataObject constructor.
@@ -50,7 +51,7 @@ class MysqlStorageData {
/** /**
* @return array * @return array
*/ */
public function getData() : array { public function getData() : iterable {
if(!empty($this->arrayData)) return $this->arrayData; if(!empty($this->arrayData)) return $this->arrayData;
if(!$this->result) return []; if(!$this->result) return [];
$this->result->data_seek(0); $this->result->data_seek(0);

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage; namespace Rmphp\Storage\Mysql;
interface MysqlStorageInterface { interface MysqlStorageInterface {
@@ -57,7 +57,7 @@ interface MysqlStorageInterface {
* @param int $count * @param int $count
* @return bool|MysqlStorageData * @return bool|MysqlStorageData
*/ */
public function read(string $sql, int $ln = 0, int $numPage = 1) : bool|MysqlStorageData; public function read(string $sql, int $ln = 0, int $numPage = 1, int $count=0) : bool|MysqlStorageData;
/** /**
* @param string $tbl * @param string $tbl