<?php
declare(strict_types=1);
$lane=getenv('PM_LANE');$root=getenv('PM_ROOT');$cfg=(static function($f){return require $f;})($root.'/application/database.php');
if($lane==='B'){$local=(static function($f){return require $f;})('/workspace/zhct/zhctproject/store/application/config/local/database.php');foreach(['hostname','database','username','password']as $k)if((string)$cfg[$k]!== (string)$local[$k])throw new RuntimeException('Not code local');if((string)(($cfg['hostport']??'')?:3306)!==(string)(($local['hostport']??'')?:3306))throw new RuntimeException('Not code local port');$dsn='mysql:host='.$cfg['hostname'].';port='.(($cfg['hostport']??'')?:3306).';dbname='.$cfg['database'].';charset=utf8mb4';}else{if($cfg['hostname']!=='127.0.0.1'||(string)$cfg['hostport']!=='5237'||$cfg['database']!=='ZHCT_APP')throw new RuntimeException('DM scope');$dsn='dm:host=127.0.0.1;port=5237;schema=ZHCT_APP';}
$db=new PDO($dsn,$cfg['username'],$cfg['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_CASE=>PDO::CASE_LOWER]);$p=$lane==='B'?'ydy_':'YDY_';
$q=static function(string $sql,array $args=[])use($db):array{$s=$db->prepare($sql);$s->execute($args);$rows=[];while($r=$s->fetch(PDO::FETCH_ASSOC)){$r=array_change_key_case($r,CASE_LOWER);foreach($r as &$v)if(is_resource($v))$v=stream_get_contents($v);unset($v);$rows[]=$r;if(count($rows)>100)throw new RuntimeException('Bounded result cap100');}return $rows;};
$check=static function(bool $ok,string $why):void{if(!$ok)throw new RuntimeException($why);};$hash=static function($v):string{return hash('sha256',serialize($v));};$save=static function($file,$v):void{file_put_contents(__DIR__.'/'.$file,json_encode($v,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));chmod(__DIR__.'/'.$file,0600);};
require_once $root.'/env.php';$business=defined('BUSINESS')&&BUSINESS!=='BUSINESS_VALUE'?(string)BUSINESS:'';
