致命错误:类mysqli

编程入门 行业动态 更新时间:2024-10-28 06:28:01
致命错误:类mysqli_stmt的对象无法转换为字符串(Fatal error: Object of class mysqli_stmt could not be converted to string)

我是PHP新手,所以这个问题一定很愚蠢。 我多次阅读代码,但无法找到有关这些错误的任何差异:

PHP可捕捉的致命错误:类mysqli_stmt的对象无法转换为80行mkt_salva_prodotti.php中的字符串

PHP可捕捉的致命错误:类mysqli_stmt的对象无法转换为线89上的mkt_salva_prodotti.php中的字符串

以下是代码:

<?php require "common/header.php" ; $token=getPar_empty("token",$_GET); if ($token=="")$token=getPar_empty("token",getallheaders()); auth($token); $nome_it=getPar_empty("nome_it",$_POST,null); $nome_en=getPar_empty("nome_en",$_POST,null); $descrizione_it=getPar_empty("descrizione_it",$_POST,null); $descrizione_en=getPar_empty("descrizione_en",$_POST,null); $imm_url=getPar_empty("imm_url",$_POST,null); $lat=getPar_empty("lat",$_POST,null); $lng=getPar_empty("lng",$_POST,null); $posto=getPar_empty("posto",$_POST,null); $id=getPar_empty("id",$_POST,null); $lingua=getPar_empty("lingua",$_POST,null); $id_produttore=getPar_empty("id_produttore",$_POST,null); $quantita_min=(integer)getPar_empty("quantita_min",$_POST,0); $quantita_max=(integer)getPar_empty("quantita_max",$_POST,0); $quantita_disp=(integer)getPar_empty("quantita_disp",$_POST,0); $costo=(float)getPar_empty("costo",$_POST,0); $tasse=(float)getPar_empty("tasse",$_POST,0); $completo_it=(integer)getPar_empty("completo_it",$_POST,1); $completo_en=(integer)getPar_empty("completo_en",$_POST,1); $lat2=getPar_empty("lat2",$_POST,null); $lng2=getPar_empty("lng2",$_POST,null); $posto2=getPar_empty("posto2",$_POST,null); $lat3=getPar_empty("lat3",$_POST,null); $lng3=getPar_empty("lng3",$_POST,null); $posto3=getPar_empty("posto3",$_POST,null); $user=getPar_empty("user",$_POST); $system=getPar_empty("system",$_POST); $out=array("res"=>"0"); $db->autocommit(FALSE); if (isset($_POST['del_ingr']) && $_POST['del_ingr']==1){ $stmt=$db->prepare("UPDATE prodotti set online=0,data_update=now(),sistema=?, utente=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sss",$system,$user,$id); $stmt->execute(); $db->commit(); $db->close(); $out["res"]="1"; echo json_encode($out); die(); } if (!$id) $id=get_a_slug($nome_it.'-'.$nome_en."_".bin2hex(openssl_random_pseudo_bytes(3))); if (!$id) die(); $stmt=$db->prepare("UPDATE prodotti set nome=?,descrizione=?,completo=? where id=? and lingua='it'"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssis", $nome_it,$descrizione_it,$completo_it,$id); if (test_execute($stmt->execute()) ) $out['it']=1; if ($db->affected_rows==0){ $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo) VALUES (?,?,?,'it',?)"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssis", $nome_it,$descrizione_it,$completo_it,$id); if (test_execute($stmt->execute())) $out['it']=1; } $stmt=$db->prepare("UPDATE prodotti set nome=? ,descrizione=?,completo=? where id=? and lingua='en'"); if (!$stmt) { log_msg($db->error); die(); } $stmt->bind_param("ssis", $nome_en,$descrizione_en,$completo_en,$id); if (test_execute($stmt->execute()) ) $out['en']=1; if ($db->affected_rows==0){ $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo) VALUES (?,?,?,'en',?)"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssis", $nome_en,$descrizione_en,$completo_en,$id); if ($stmt->execute()) $out['en']=1; } if ($imm_url && $imm_url!=IMAGE_PLACEHOLDER && file_exists(ROOT_DIR.$imm_url)){ $stmt=$db->prepare("select imm_url from prodotti where id=? LIMIT 0,1"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("s", $id); $stmt->execute(); $row=fetchArray($stmt); $stmt->close(); if (count($row)==1){ offline_s3_archivio($row[0]["imm_url"],$system,$user); } $array=null; $id_s3=crea_s3_archivio_immagini(ROOT_DIR.$imm_url,$system,$user,$array,false); if ($id_s3==0) { $db->rollback (); die(); } $stmt=$db->prepare("UPDATE prodotti set imm_url=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ss", $id_s3,$id); if ($stmt->execute()) { $out['file']=$array["big"]; $out['archive']=$id_s3; } } $posti=array(); if ($lat && $lng && $posto){ array_push($posti,array("lat"=>$lat,"lng"=>$lng,"posto"=>$posto)); } if ($lat2 && $lng2 && $posto2){ array_push($posti,array("lat"=>$lat2,"lng"=>$lng2,"posto"=>$posto2)); } if ($lat3 && $lng3 && $posto3){ array_push($posti,array("lat"=>$lat3,"lng"=>$lng3,"posto"=>$posto3)); } if ($posti && count($posti)>0){ $to=json_encode($posti); $stmt=$db->prepare("UPDATE prodotti set mappa=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ss", $to,$id); if ($stmt->execute()) $out['mappa']=$to; } $stmt=$db->prepare("UPDATE prodotti set quantita_min=?,quantita_max=?,quantita_disp=?,costo=?,tasse=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("iiidds", $quantita_min,$quantita_max,$quantita_disp,$costo,$tasse,$id); if ($stmt->execute()) $out['dati']=1; if (isset($out['en']) && isset($out['it']) && $out['en']==1 && $out['it']==1) { $out["res"]="1"; $out["id"]=$id; } $stmt=$db->prepare("UPDATE prodotti set data_update=now(),sistema=?, utente=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sss", $system,$user,$id); $stmt->execute(); $stmt->close(); $db->commit(); $db->close(); echo json_encode($out); ?>

请帮助我。 谢谢!

I'm new to PHP so this question must be quite dumb. I've read the code many times but I'm unable to find any discrepancy about those errors:

PHP Catchable fatal error: Object of class mysqli_stmt could not be converted to string in mkt_salva_prodotti.php on line 80

PHP Catchable fatal error: Object of class mysqli_stmt could not be converted to string in mkt_salva_prodotti.php on line 89

Following is the code:

<?php require "common/header.php" ; $token=getPar_empty("token",$_GET); if ($token=="")$token=getPar_empty("token",getallheaders()); auth($token); $nome_it=getPar_empty("nome_it",$_POST,null); $nome_en=getPar_empty("nome_en",$_POST,null); $descrizione_it=getPar_empty("descrizione_it",$_POST,null); $descrizione_en=getPar_empty("descrizione_en",$_POST,null); $imm_url=getPar_empty("imm_url",$_POST,null); $lat=getPar_empty("lat",$_POST,null); $lng=getPar_empty("lng",$_POST,null); $posto=getPar_empty("posto",$_POST,null); $id=getPar_empty("id",$_POST,null); $lingua=getPar_empty("lingua",$_POST,null); $id_produttore=getPar_empty("id_produttore",$_POST,null); $quantita_min=(integer)getPar_empty("quantita_min",$_POST,0); $quantita_max=(integer)getPar_empty("quantita_max",$_POST,0); $quantita_disp=(integer)getPar_empty("quantita_disp",$_POST,0); $costo=(float)getPar_empty("costo",$_POST,0); $tasse=(float)getPar_empty("tasse",$_POST,0); $completo_it=(integer)getPar_empty("completo_it",$_POST,1); $completo_en=(integer)getPar_empty("completo_en",$_POST,1); $lat2=getPar_empty("lat2",$_POST,null); $lng2=getPar_empty("lng2",$_POST,null); $posto2=getPar_empty("posto2",$_POST,null); $lat3=getPar_empty("lat3",$_POST,null); $lng3=getPar_empty("lng3",$_POST,null); $posto3=getPar_empty("posto3",$_POST,null); $user=getPar_empty("user",$_POST); $system=getPar_empty("system",$_POST); $out=array("res"=>"0"); $db->autocommit(FALSE); if (isset($_POST['del_ingr']) && $_POST['del_ingr']==1){ $stmt=$db->prepare("UPDATE prodotti set online=0,data_update=now(),sistema=?, utente=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sss",$system,$user,$id); $stmt->execute(); $db->commit(); $db->close(); $out["res"]="1"; echo json_encode($out); die(); } if (!$id) $id=get_a_slug($nome_it.'-'.$nome_en."_".bin2hex(openssl_random_pseudo_bytes(3))); if (!$id) die(); $stmt=$db->prepare("UPDATE prodotti set nome=?,descrizione=?,completo=? where id=? and lingua='it'"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssis", $nome_it,$descrizione_it,$completo_it,$id); if (test_execute($stmt->execute()) ) $out['it']=1; if ($db->affected_rows==0){ $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo) VALUES (?,?,?,'it',?)"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssis", $nome_it,$descrizione_it,$completo_it,$id); if (test_execute($stmt->execute())) $out['it']=1; } $stmt=$db->prepare("UPDATE prodotti set nome=? ,descrizione=?,completo=? where id=? and lingua='en'"); if (!$stmt) { log_msg($db->error); die(); } $stmt->bind_param("ssis", $nome_en,$descrizione_en,$completo_en,$id); if (test_execute($stmt->execute()) ) $out['en']=1; if ($db->affected_rows==0){ $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo) VALUES (?,?,?,'en',?)"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssis", $nome_en,$descrizione_en,$completo_en,$id); if ($stmt->execute()) $out['en']=1; } if ($imm_url && $imm_url!=IMAGE_PLACEHOLDER && file_exists(ROOT_DIR.$imm_url)){ $stmt=$db->prepare("select imm_url from prodotti where id=? LIMIT 0,1"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("s", $id); $stmt->execute(); $row=fetchArray($stmt); $stmt->close(); if (count($row)==1){ offline_s3_archivio($row[0]["imm_url"],$system,$user); } $array=null; $id_s3=crea_s3_archivio_immagini(ROOT_DIR.$imm_url,$system,$user,$array,false); if ($id_s3==0) { $db->rollback (); die(); } $stmt=$db->prepare("UPDATE prodotti set imm_url=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ss", $id_s3,$id); if ($stmt->execute()) { $out['file']=$array["big"]; $out['archive']=$id_s3; } } $posti=array(); if ($lat && $lng && $posto){ array_push($posti,array("lat"=>$lat,"lng"=>$lng,"posto"=>$posto)); } if ($lat2 && $lng2 && $posto2){ array_push($posti,array("lat"=>$lat2,"lng"=>$lng2,"posto"=>$posto2)); } if ($lat3 && $lng3 && $posto3){ array_push($posti,array("lat"=>$lat3,"lng"=>$lng3,"posto"=>$posto3)); } if ($posti && count($posti)>0){ $to=json_encode($posti); $stmt=$db->prepare("UPDATE prodotti set mappa=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ss", $to,$id); if ($stmt->execute()) $out['mappa']=$to; } $stmt=$db->prepare("UPDATE prodotti set quantita_min=?,quantita_max=?,quantita_disp=?,costo=?,tasse=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("iiidds", $quantita_min,$quantita_max,$quantita_disp,$costo,$tasse,$id); if ($stmt->execute()) $out['dati']=1; if (isset($out['en']) && isset($out['it']) && $out['en']==1 && $out['it']==1) { $out["res"]="1"; $out["id"]=$id; } $stmt=$db->prepare("UPDATE prodotti set data_update=now(),sistema=?, utente=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sss", $system,$user,$id); $stmt->execute(); $stmt->close(); $db->commit(); $db->close(); echo json_encode($out); ?>

Kindly help me on this. Thank you!

最满意答案

好吧,我解决了它,但我无法解决这个'id'变量的新问题:

截断错误的DOUBLE值:'1464261692_5f2d6cd474'

<?php require "common/header.php" ; $token=getPar_empty("token",$_GET); if ($token=="")$token=getPar_empty("token",getallheaders()); auth($token); $nome_it=getPar_empty("nome_it",$_POST,null); $nome_en=getPar_empty("nome_en",$_POST,null); $descrizione_it=getPar_empty("descrizione_it",$_POST,null); $descrizione_en=getPar_empty("descrizione_en",$_POST,null); $imm_url=getPar_empty("imm_url",$_POST,null); $id=getPar_empty("id",$_POST,null); $lingua=getPar_empty("lingua",$_POST,null); $id_produttore=getPar_empty("id_produttore",$_POST,null); $quantita_min=(integer)getPar_empty("quantita_min",$_POST,0); $quantita_max=(integer)getPar_empty("quantita_max",$_POST,0); $quantita_disp=(integer)getPar_empty("quantita_disp",$_POST,0); $costo=(float)getPar_empty("costo",$_POST,0); $tasse=(float)getPar_empty("tasse",$_POST,0); $completo_it=(integer)getPar_empty("completo_it",$_POST,1); $completo_en=(integer)getPar_empty("completo_en",$_POST,1); $lat=getPar_empty("lat",$_POST,null); $lng=getPar_empty("lng",$_POST,null); $posto=getPar_empty("posto",$_POST,null); $user=getPar_empty("user",$_POST); $system=getPar_empty("system",$_POST); $out=array("res"=>"0"); $db->autocommit(FALSE); if (isset($_POST['del_ingr']) && $_POST['del_ingr']==1){ $stmt=$db->prepare("UPDATE prodotti set online=0,data_update=now(),sistema=?, utente=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sss",$system,$user,$id); $stmt->execute(); $db->commit(); $db->close(); $out["res"]="1"; echo json_encode($out); die(); } $stmt=$db->prepare("UPDATE prodotti set nome=?,descrizione=?,completo=?,quantita_min=?,quantita_max=?,quantita_disp=?,costo=?,tasse=? where id=? and lingua='it'"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssisiiidd", $nome_it,$descrizione_it,$completo_it,$id,$quantita_min,$quantita_max,$quantita_disp,$costo,$tasse); if (test_execute($stmt->execute()) ) $out['it']=1; if ($db->affected_rows==0){ $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo,quantita_min,quantita_max,quantita_disp,costo,tasse) VALUES (?,?,?,'it',?,?,?,?,?,?)"); $id=generateid(); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssisiiidd", $nome_it,$descrizione_it,$completo_it,$id,$quantita_min,$quantita_max,$quantita_disp,$costo,$tasse); if (test_execute($stmt->execute())) $out['it']=1; } $stmt=$db->prepare("UPDATE prodotti set nome=?,descrizione=?,completo=?,quantita_min=?,quantita_max=?,quantita_disp=?,costo=?,tasse=? where id=? and lingua='en'"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssisiiidd", $nome_en,$descrizione_en,$completo_en,$id,$quantita_min,$quantita_max,$quantita_disp,$costo,$tasse); if (test_execute($stmt->execute()) ) $out['en']=1; if ($db->affected_rows==0){ $stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo,quantita_min,quantita_max,quantita_disp,costo,tasse) VALUES (?,?,?,'en',?,?,?,?,?,?)"); $id=generateid(); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssisiiidd", $nome_en,$descrizione_en,$completo_en,$id,$quantita_min,$quantita_max,$quantita_disp,$costo,$tasse); if (test_execute($stmt->execute())) $out['en']=1; } if ($imm_url && $imm_url!=IMAGE_PLACEHOLDER && file_exists(ROOT_DIR.$imm_url)){ $stmt=$db->prepare("select imm_url from prodotti where id=? LIMIT 0,1"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("s", $id); $stmt->execute(); $row=fetchArray($stmt); $stmt->close(); if (count($row)==1){ offline_s3_archivio($row[0]["imm_url"],$system,$user); } $array=null; $id_s3=crea_s3_archivio_immagini(ROOT_DIR.$imm_url,$system,$user,$array,false); if ($id_s3==0) { $db->rollback (); die(); } $stmt=$db->prepare("UPDATE prodotti set imm_url=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ss", $id_s3,$id); if ($stmt->execute()) { $out['file']=$array["big"]; $out['archive']=$id_s3; } } $posti=array(); if ($lat && $lng && $posto){ array_push($posti,array("lat"=>$lat,"lng"=>$lng,"posto"=>$posto)); } if ($posti && count($posti)>0){ $to=json_encode($posti); $stmt=$db->prepare("UPDATE prodotti set mappa=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ss", $to,$id); if ($stmt->execute()) $out['mappa']=$to; } if (isset($out['en']) && isset($out['it']) && $out['en']==1 && $out['it']==1) { $out["res"]="1"; $out["id"]=$id; } $stmt=$db->prepare("UPDATE prodotti set data_update=now(),sistema=?, utente=? where id=?"); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sss", $system,$user,$id); $stmt->execute(); $stmt->close(); $db->commit(); $db->close(); echo json_encode($out); ?>

Ok! Problem solved. I'd to change variable order:

$stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo,quantita_min,quantita_max,quantita_disp,costo,tasse) VALUES (?,?,?,'it',?,?,?,?,?,?)"); $id=generateid(); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("ssisiiidd", $nome_it,$descrizione_it,$id,$completo_it,$quantita_min,$quantita_max,$quantita_disp,$costo,$tasse); if (test_execute($stmt->execute())) $out['it']=1;

Instead of:

$stmt=$db->prepare("INSERT IGNORE INTO prodotti (nome,descrizione,id,lingua,completo,quantita_min,quantita_max,quantita_disp,costo,tasse) VALUES (?,?,?,'it',?,?,?,?,?,?)"); $id=generateid(); if (!$stmt) { log_msg($db->error); $db->rollback (); die(); } $stmt->bind_param("sssiiiidd", $nome_it,$descrizione_it,$id,$completo_it,$quantita_min,$quantita_max,$quantita_disp,$costo,$tasse); if (test_execute($stmt->execute())) $out['it']=1;

更多推荐

本文发布于:2023-07-26 19:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   mysqli

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!