I am doing a sentence with PDO in PHP and an error occurs when assigning the values.
$request =
[
'lang' => ['value'=>'es','type'=>PDO::PARAM_STR, 'length'=>2],
'page' => ['value'=>'home','type'=>PDO::PARAM_STR, 'length'=>null]
];
foreach ($request as $key => $value)
{
$_value = $request[$key]['value'];
$_type = $request[$key]['type'];
$_len = $request[$key]['length'];
// BindParam
if($_len == null)
$beforeQuery ->bindParam( $key, $_value ,$_type );
else
$beforeQuery ->bindParam( $key, $_value, $_type, $_len );
// BindValue
$beforeQuery ->bindValue( ':'.$key, $_value ,$_type );
}
Sentence
SELECT * FROM page WHERE lang_id=:lang AND page=:page
Debug
With BindParam I get this result that is not the correct one but,
SELECT * FROM interface WHERE lang='home' AND page='home'
with BindValue if he gives me the sentence correctly.
SELECT * FROM interface WHERE lang='es' AND page='home'