Mysql问题及解决——Error code2014

本文介绍了一种在MySQLWorkbench中执行存储过程时遇到的错误(ErrorCode:2014Commandsoutofsync;youcan'trunthiscommandnow),并提供了一个具体的存储过程示例。尽管尝试调整设置来解决问题,但该问题仍然存在。值得注意的是,在Navicat中运行相同的存储过程则不会出现此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

使用mysql workbench执行一段存储过程,如下,实现分段插入的功能,但是会出现Error Code: 2014 Commands out of sync; you can't run this command now,

设定SQL editor——Query Editor——Max number of result set:从10改到500,会出现同样的错误,但是出现的时间不一样。

同样的代码在navicat上实现没有问题。

CREATE DEFINER=`root`@`localhost` PROCEDURE `test`()

BEGIN
    #Routine body goes here...
    DECLARE no_more_record INT DEFAULT 0;
    DECLARE session_record text;
    DECLARE numberofid int DEFAULT 0;
    declare nmbid int default 0;
    DECLARE cur_record CURSOR for select distinct session_trace from exact_reg_users;#the important part
    
  #DECLARE cur_record CURSOR for select ordertime from cookie_order;
    DECLARE  CONTINUE HANDLER FOR NOT FOUND  SET  no_more_record = 1; /*这个是个条件处理,针对NOT FOUND的条件,当没有记录时赋值为1*/
    open cur_record;
    fetch cur_record into session_record;

    drop table if exists cookie_to_id;
    create table if not exists cookie_to_id
    (
        id VARCHAR(255),
        session_changed_users VARCHAR(255)
    );
    set @numberofid=1;
    while no_more_record !=1 DO
        fetch cur_record into session_record;
    select session_record;
        SELECT DISTINCT tuniu_user_id,session_trace FROM webflow1207 where session_trace = session_record;
        select @numberofid:=COUNT(DISTINCT tuniu_user_id) from webflow1207 where session_trace = session_record;
        
        /*if @numberofid = 2 then
        INSERT into cookie_to_id(id,session_changed_users)
        SELECT DISTINCT tuniu_user_id,session_trace FROM webflow1207 where session_trace = session_record;
        SELECT "insert success";
        end if;*/
                
    end WHILE;
    CLOSE cur_record;

END

解决方法:

尚不明确。

在PHP中将MySQL数据展示到前端页面通常需要经过以下几个步骤: 1. **连接数据库**:首先,使用`mysqli_connect()` 或 `PDO` 函数建立与MySQL服务器的连接。例如: ```php $servername = "localhost"; $username = "your_username"; $password = "your_password"; $dbname = "your_database"; $conn = mysqli_connect($servername, $username, $password, $dbname); // 检查连接是否成功 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } ``` 2. **查询数据**:确定好SQL查询语句从数据库获取所需的数据。比如获取所有文章信息: ```php $sql = "SELECT * FROM articles"; $result = mysqli_query($conn, $sql); ``` 3. **处理结果**:如果查询成功,使用`mysqli_fetch_assoc()`等函数逐行获取并处理数据: ```php while ($row = mysqli_fetch_assoc($result)) { // 这里可以对每一条数据做你想做的事情,如添加到数组或对象中 $data[] = $row; } ``` 4. **显示数据**:最后,你可以选择适合的方式将数据传递给HTML模板或者直接输出JSON,然后前端通过JavaScript接收并在页面上渲染。例如,使用`json_encode()`将数据转换为JSON: ```php echo json_encode($data); ``` 或者使用PHP内置的模板引擎(如Twig、Smarty等),或者直接在HTML中循环输出数据。 ```html <!-- 使用PHP echo将数据插入到HTML中 --> <ul> <?php foreach ($data as $item): ?> <li>ID: <?php echo $item['id']; ?>,Title: <?php echo $item['title']; ?></li> <?php endforeach; ?> </ul> ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值