How to fix ‘bind_param() ’ error in PHP with PDO mysql conection

Gabriel S Lessa

if anyone can help me with the problem that is happening, I am very grateful. The error would be with bind_param () using PDO connection.

Fatal error: Call to undefined method PDOStatement::bind_param() in line25

setlocale(LC_MONETARY,"en_US");
if(isset($_POST["id"])) {
foreach($_POST as $key => $value){
    $product[$key] = filter_var($value, FILTER_SANITIZE_STRING);
}   

$statement = app('db')->prepare("SELECT as_produtos.nome, as_produtos.preco FROM as_produtos WHERE id = ? LIMIT 1");
$statement->bind_param('s', $product['id']);
$statement->execute();
$statement->bind_result($product_name, $product_price);

while($statement->fetch()){ 
    $product["product_name"] = $product_name;
    $product["product_price"] = $product_price;     
    if(isset($_SESSION["products"])){ 
        if(isset($_SESSION["products"][$product['id']])) {              
            $_SESSION["products"][$product['id']]["product_qty"] = $_SESSION["products"][$product['id']]["product_qty"] + $_POST["product_qty"];                
        } else {
            $_SESSION["products"][$product['id']] = $product;
        }           
    } else {
        $_SESSION["products"][$product['id']] = $product;
    }   
}   
$total_product = count($_SESSION["products"]);
die(json_encode(array('products'=>$total_product)));
}

if(isset($_GET["remove_code"]) && isset($_SESSION["products"])) {
$product_code  = filter_var($_GET["remove_code"], FILTER_SANITIZE_STRING);
if(isset($_SESSION["products"][$product_code])) {
    unset($_SESSION["products"][$product_code]);
}   
$total_product = count($_SESSION["products"]);
die(json_encode(array('products'=>$total_product)));
}

if(isset($_GET["update_quantity"]) && isset($_SESSION["products"])) {   
if(isset($_GET["quantity"]) && $_GET["quantity"]>0) {       
    $_SESSION["products"][$_GET["update_quantity"]]["product_qty"] = $_GET["quantity"]; 
}
$total_product = count($_SESSION["products"]);
die(json_encode(array('products'=>$total_product)));
}
Dsh

I guess you meant to call bindParam.
Also there's no function called bind_result (Check: What is the equivalent of bind_result on PDO).
Furthermore, you trying to bind param (':s'), but there's '?' in your request string.

$statement = app('db')->prepare("SELECT as_produtos.nome, as_produtos.preco FROM as_produtos WHERE id = :s LIMIT 1");  
$statement->bindParam(':s', $product['id']);

Or use bindValue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related