mysql - MySQL:准备语句失败
问题描述
我有一个带函数的类,它准备 SQL 语句将数据放入数据库,但是有一个错误我无法弄清楚,为什么会发生?
public function vnos_narocila($user) //, $hvrsta_narocila, $hlastna_nabava, $hos, $hsm_dn, $hoe, $hartikel1, $hkolicina_artikel1, $hem1, $hartikel2, $hkolicina_artikel2, $hem2, $hartikel3, $hkolicina_artikel3, $hem3, $hartikel4, $hkolicina_artikel4, $hem4, $hartikel5, $hkolicina_artikel5, $hem5, $hartikel6, $hkolicina_artikel6, $hem6, $hartikel7, $hkolicina_artikel7, $hem7, $hartikel8, $hkolicina_artikel8, $hem8, $hartikel9, $hkolicina_artikel9, $hem9, $hartikel10, $hkolicina_artikel10, $hem10, $hprevzemnik, $hopomba, $hzeljen_datum)
{
$sql = "SELECT * FROM nabava ORDER BY id_nabava DESC LIMIT 1"; //pridobitev zaporedne številke v letu
if( !$this->stmt = $this->mysqli->prepare($sql) )
throw new Exception("MySQL Prepare statement failed: ".$this->mysqli->error);
$this->stmt->execute();
$zadnji_zapis = $this->stmt->get_result();
$zadnji_zapis = $zadnji_zapis-> fetch_array();
$leto = date('Y');
if ( !$zadnji_zapis or $zadnji_zapis[leto] != $leto)
$zap_st=1;
else
$zap_st = $zadnji_zapis[zap_st]+1;
$narocilo = "N-".$zap_st."-".$hoe."/".$leto; //kreiranje številke naročila
$sql_vnos = "INSERT INTO nabava (vrsta_narocila, lastna_dobava, os, sm_dn, prevzemnik, opomba, zeljen_datum_dobave, narocilo, uporabnik, datum_vnosa, zap_st, oe, leto) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ? )";
if( !$this->stmt = $this->mysqli->prepare($sql_vnos) )
throw new Exception("MySQL Prepare statement failed: ".$this->mysqli->error);
$this->stmt->bind_param("iiisssisiiii", $hvrsta_narocila, $hlastna_dobava, $hos, $hsm_dn, $hprevzemnik, $hopomba, $hzeljen_datum, $narocilo, $user, $zap_st, $hoe, $leto );
if( $this->stmt->execute() )
return $this->stmt->insert_id;
return $narocilo;
}
这是错误:
致命错误:未捕获的异常:MySQL Prepare 语句失败:在 /var/www/html/intra_komunalaBrezice/skripte/nabava.php:111 堆栈跟踪:#0 /var/www/html/intra_komunalaBrezice/nabava_vnos.php(27): nabava ->vnos_narocila(1, '1', '1', '1', '200401', '1005', '1', '1', '1', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' , '', '', '', '', '', '', 'test', 'test', '2018-07-04') #1 {main} 在 /var/www/html/intra_komunalaBrezice 中抛出/skripte/nabava.php 在第 111 行
请帮忙...
解决方案
列数和传递的值数有误。
对不起,我应该看看。
推荐阅读
- python - 通过 Paramiko SFTP 上传文件不起作用
- python - 使用 python 模拟镜头光晕和色差
- java - 如何更改 Eclipse 显示设置?
- python-3.x - 作为脚本启动时,模块“子进程”没有属性“运行”
- ios - 在 swift 4 iOS 中截取整个 WebView 的屏幕截图
- reactjs - 在 ReactJS 中使用 .fetch() 上传文件
- facebook - 使用 react-native-fbsdk 分享视频
- php - 在 PHP 中使用 wp_mail 发送多个附件
- javascript - 数据表自定义过滤 AJAX 数据函数不调用 AJAX
- r - 如何使用 R 中的钻头为集群执行散点图?