douzi8548 2015-05-06 16:57
浏览 61
已采纳

$ mysqli-insert_id没有正确递增

I am trying to use $mysqli->insert_id to rename a file so my program can create more than one file. Instead it just creates one file with an id of 0 and each time it overwrites that file instead of creating a new one. I am wondering if I need to increment $mysli->insert_id or something.

But basically I want each file to be named the 'job_id'.fasta. Right now they all are 0.fasta.

I am confused because when I use mysqli->insert_id for my insert statement it correctly assigns job_ids to each new job. So when I SELECT * FROM Job I get a huge list of all the jobs 1-100. I want the files that are created from a job to be called the job_id instead of just 0.

Here is the code that I have.

<?php
if(isset($_POST['submit'])){
//      echo "submit1";
            //declare variables to what the user defines them as

            $db = $_POST['database'];
            $evalue = $_POST['evalue'];
            $sequence = $_POST['BlastSearch'];
            $hits = $_POST['hits'];


            //insert the values into the database



            //create a new .fasta file and put the sequence the user wants to search for in that file
            $file = 'uploads/'.$mysqli->insert_id.'.fasta';
            $current = $_POST['BlastSearch'];
            file_put_contents($file, $current);

            //execute the BLAST Tool
            // Do this execute statement if the user inputs his own sequence. (Use new.fasta)


?>

So the insert_id increments for inserting an id into the database for job_id but it doesnt increment in my $file = 'uploads/'.$mysqli->id or my exec function.

  • 写回答

1条回答 默认 最新

  • doumei1955 2015-05-06 17:22
    关注

    I guess you missed the idea somewhere.

    It is not clear what is your problem according to your code.

    Let me explain why I can't understand your issue.

    Here is transformed fragment of your code:

    $mysqli->query("INSERT INTO `Job` (`uid`, `input`, `status`, `start_time`, `finish_time`) VALUES ('1', '" . $sequence . "', 'running' , NOW(), NOW())");
    $insertedJobId = $mysqli->insert_id;
    $mysqli->query("INSERT INTO `BLAST`(`db_name`, `evalue`, `job_id`) VALUES ('" . $db . "','" . $evalue . "', '".$insertedJobId."')") or die(mysqli_error($mysqli));
    $insertedBlastId = $mysqli->insert_id; 
    
    //execute the BLAST Tool
    // Do this execute statement if the user inputs his own sequence. (Use new.fasta)
    
    exec('/students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/public_html/home/uploads/'.$insertedBlastId.'.fasta -m'.$evalue.' -o outputSEQ -v'.$hits.' -b'.$hits);
    

    So which insert_id id is not incremented? $insertedJobId or $insertedBlastId ?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化