index/src/Data/MariaDB/MariaDBParameter.php

82 lines
1.7 KiB
PHP

<?php
// MariaDBParameter.php
// Created: 2021-05-02
// Updated: 2022-02-02
namespace Index\Data\MariaDB;
use Index\Data\DbTools;
use Index\Data\DbType;
/**
* Represents a bound parameter.
*/
class MariaDBParameter {
private int $ordinal;
private int $type;
private mixed $value;
/**
* Create a new MariaDBParameter.
*
* @param int $ordinal Parameter number.
* @param int $type DbType number.
* @param mixed $value Value to bind.
* @return MariaDBParameter A new parameter instance.
*/
public function __construct(int $ordinal, int $type, mixed $value) {
$this->ordinal = $ordinal;
if($type == DbType::AUTO)
$type = DbTools::detectType($value);
$this->type = $type;
$this->value = $type === DbType::NULL ? null : $value;
}
/**
* Gets the parameter number.
*
* @return int Parameter number.
*/
public function getOrdinal(): int {
return $this->ordinal;
}
/**
* Gets the DbType of for the parameter.
*
* @return int DbType.
*/
public function getDbType(): int {
return $this->type;
}
/**
* Gets the type character for the mysqli bind.
*
* @return string Type character.
*/
public function getBindType(): string {
switch($this->type) {
case DbType::INTEGER:
return 'i';
case DbType::FLOAT:
return 'd';
case DbType::BLOB:
return 'b';
default:
return 's';
}
}
/**
* Gets the value for the parameter.
*
* @return mixed Value.
*/
public function getValue(): mixed {
return $this->value;
}
}