Mysql从声明变量插入插入 [英] Mysql insert from declare variable error
问题描述
我正在尝试将数据插入表中。我要插入的一些字段来自该表。所以我创建一个临时变量来定义数据,然后在查询中调用该变量。当我尝试从sqlyog执行它没关系,但当我尝试使用PHP执行它我得到一个错误消息
Hi, I'm trying to insert a data to a table. some of the field that i want to insert are come from that table. so i create a temporary variable to define the data, then call the variable in the query. when i try to execute from sqlyog it's fine but when i try to execute it using php i get an error message
错误你有一个错误在你的SQL语法中;检查与MariaDB服务器版本对应的手册,以便在eslii_logicalframework中使用'SELECT @lvl:= level + 1'附近使用正确的语法,其中id_framework ='5'; '第2行
ERROR You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT @lvl := level+1 from eslii_logicalframework where id_framework='5'; ' at line 2
我的PHP代码
my php code
$sq_insert="SELECT @kdfrm := CONCAT(kode_framework,'.".$nomor_urut."') from eslii_logicalframework where id_framework='".$lookup_id."';
SELECT @lvl := level+1 from eslii_logicalframework where id_framework='".$lookup_id."';
insert into eslii_logicalframework
(
kode_framework,
no,
level,
id_jenis,
logical_framework,
indikator_framework,
unitkey
)values
(
@kdfrm,
'".$nomor_urut."',
@lvl,
'".$data_post_select."',
'".$data_post."',
'".$data_post_ind."',
'".$unitkey_login."'
);";
if (!$result = mysqli_query($conmysql,$sq_insert)) {
echo"<div class='alert alert-mini alert-danger margin-bottom-30'> ERROR ".mysqli_error($conmysql)."</div>";
}
我的尝试:
i只尝试执行php代码
What I have tried:
i only try to execute the php code
推荐答案
sq_insert =SELECT @kdfrm:= CONCAT(kode_framework,'。。
sq_insert="SELECT @kdfrm := CONCAT(kode_framework,'.".
nomor_urut。')来自eslii_logicalframework,其中id_framework ='。
nomor_urut."') from eslii_logicalframework where id_framework='".
lookup_id。';
SELECT @lvl:= level + 1来自eslii_logicalframework其中id_framework ='。
lookup_id."'; SELECT @lvl := level+1 from eslii_logicalframework where id_framework='".
这篇关于Mysql从声明变量插入插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!