PDO param:
$cto=new PDO("mysql:host=$servername;dbname=$dbname",$username,$password);
Interacting with data base
$csql=$cto->prepare("INSERT INTO `users`(`username`, `password`, `class`, `is_on`, `time_log`, `IP`)
VALUES (:name,:pass,:class,0,0,'0')");
$pr=[
':name' => $_POST['username'],
":pass" => $_POST['password'],
":class" => $_POST["class"],
];
$csql->execute($pr);
$cto=null;
My question is ,i am currently using array $pr in execute,could i pass this array with using bindParam
$csql->bindParam($pr);
$csql->exec();
Thank you for your time.
You can use bindParam() in single line by this way:
$csql=$cto->prepare("INSERT INTO `users`(`username`, `password`, `class`, `is_on`, `time_log`, `IP`)
VALUES (:name,:pass,:class,0,0,'0')");
//Looping for all values into array...
foreach ($pr as $key => &$val) {
$csql->bindParam($key, $val);
}
$csql->execute();
Hope this will help you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With