$promo_mask = 'XXXX-5555-XXXX-5555';
$mask_count = substr_count($promo_mask, 'X');
$promo = $promo_mask;
$chars = '12345ABCDEFGHIJKLMNOPQRSTUVWXYZ67890';
$hashpromo = '';
for($ichars = 1; $ichars <= $mask_count; ++$ichars) {
$random = str_shuffle($chars);
$promo = preg_replace('/X/', $random[$ichars], $promo, 1);
}
echo $promo;
return [
'host' => 'localhost';
'port' => 3306;
'user' => 'root';
'password' => 'ПАРОЛЬ';
'db' => 'БАЗА';
'authme_table' => 'users';
];
class Config {
public $host;
public $user;
// ...
public function __construct(array $conf){
$this->host = $conf['host'];
$this->user = $conf['user'];
// ...
}
}
class AuthController {
protected $config;
public function __construct(Config $config){
$this->config = $config
}
}
$conf = include "/engine/data/dbconfig.php";
$config = new Config($conf);
$constroller = new AuthController($config);
class DbConnection
{
private string $userName;
private string $password;
private string $dbname;
public function __construct(string $userName, string $password, string $dbName)
{
$this->userName = $userName;
$this->password = $password;
$this->dbname = $dbName;
}
}
class AuthController
{
private DbConnection $dbConnection;
public function __construct(DbConnection $connection)
{
$this->dbConnection = $connection;
}
}
$dbSettings = include('dbconfig.php');
$connection = new DbConnection($dbSettings['login'], $dbSettings['password'], $dbSettings['dbName'] );
$controller = new AuthController($connection);
return [
'login'=>'myLogin',
'password'=>'myPassword',
'dbName'=>'myDbName'
];
Use findAll if you don't want to add any conditions (but you want to order or limit... )
<?php $query = R::find( 'products', 'owner = :login', [':login' => $login]);
foreach($query as $item):
?>
<div class="prod-element">
<div class="prod-id" hidden><?=$item['id']?></div>
<div class="prod-type"><?=$item['type']?></div>
<div class="prod-name"><?=$item['name']?></div>
<div class="prod-desc"><?=$item['description']?></div>
<div class="prod-price"><?=$item['price']?></div>
<div class="prod-buy"><a class="button" href="#">РЕДАКТИРОВАТЬ</a></div>
</div>
<?php
endforeach;
?>