Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:21:21+00:00 2026-06-18T09:21:21+00:00

I am using codeigniter and mysql and i am trying to get some data

  • 0

I am using codeigniter and mysql and i am trying to get some data from mssql server and updating to my system. Its very slow. please let me know if anything wrong i am doing..

class systemupdate extends MY_Controller{

    function systemupdate() {      
        return parent::MY_Controller();
    }

    function index(){
        $message = '';                                                                                   
        $message = "CRON Information::COMMON INVENTORY SYSTEM: QUANTITY UPDATE FOR TRADE WH STARTED.";
        log_message('info', $message);  
        $this->load->model("cis/sapinventorymodel");
        $objMainResult = $this->sapinventorymodel->FetchDetailsByUnit(420);
        $mainResult = json_decode($objMainResult);
        if((isset($mainResult)) && ($mainResult->results > 0))  
        {
            $this->load->model("cron/systemupdatemodel");
            foreach($mainResult->rows as $main)
            {
                $arrQuantity = '';
                $arrQuantity = $this->systemupdatemodel->FetchTradeWhQuantity($main->number);
                if((isset($arrQuantity)) && (count($arrQuantity) > 0))
                {
                    if((isset($arrQuantity[0]->quantity)) && ($arrQuantity[0]->quantity != NULL)){
                        $objMainResult = $this->sapinventorymodel->SaveTradeWhQuantity($main->a_umber, $main->a_plant,
                                                                                     $main->a_unit,$arrQuantity[0]->quantity);
                    }
                }   
            }
        }
        $message = "CRON Information::COMMON INVENTORY SYSTEM: QUANTITY UPDATE FOR TRADE WH FINSIHED.";
        log_message('info', $message);      
    }   
}   

Here is the model

class systemupdatemodel extends MY_Model {

    function systemupdatemodel() {
        parent::__construct();
        $CI->sapData    =   $this->load->database("sapinventory", TRUE);
        $this->sapData  =   &$CI->sapData;
    }

    function FetchTradeWhQuantity($p_intNumber){

        $query = $this->sapData->query("SELECT quantity FROM master1 WHERE NUMBER = '$p_intNumber'");
            if(($query->num_rows() > 0) && ($query->num_rows() == 1)){
                return $query->result();
            }else
            {
                $query1 = $this->sapData->query("SELECT  quantity FROM master2 WHERE EANNUMBER = '$p_intNumber'");
                if(($query1->num_rows() > 0) && ($query1->num_rows() == 1)){
                    return $query1->result();
                }                   
            }                                       
    }
}   

Total number of records are 7857 i.e this many times its in loop. sapinventory is a mssql server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:21:22+00:00Added an answer on June 18, 2026 at 9:21 am

    FetchTradeWhQuantity and SaveTradeWhQuantity does a lot of runs in this case. That means (probably) at least 3 mysql queries per row. If you’d consider running this through 1 or 2 big queries instead, your performance would go up very noticeable.

    Now this might be something easy to do, or something hard to do.

    For instance;

    function FetchTradeWhQuantity($p_intNumber){ ... }
    

    Could be

    function FetchTradeWhQuantity($p_intNumber) {
    
        $query = $this->sapData->query("
    
                               SELECT quantity
                               FROM master 1
                               WHERE NUMBER = '{$p_intNumber}'
                               UNION
                               SELECT quantity
                               FROM master2
                               WHERE EANNUMBER = '{$p_intNumber}'
    
                                       ");
    
        if ($query->num_rows() == 1)
            return $query->result();
    
    }
    

    But the best thing you can do is to do all of this with 2-3 queries only. Fetch all data, use their IDs and run a UPDATE or INSERT INTO ... ON DUPLICATE KEY UPDATE. Then the server only have to connect to the mysql database a few times and doesn’t have to play pinball with the php for each little row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Codeigniter to insert some data into a MySQL table. However, the single
Using Codeigniter, any numeric data returned from my MySQL database is returned as strings.
I am trying to save data from my xml file into the mysql database
From within my scrip.js file, I'm using jquery $.post function to post some data
I'm trying to dynamically create tables in MySQL , using CodeIgniter PHP framework: if($colname
I am using latest codeigniter and trying to call stored procedure from my model.
i want to make rating system for my website using codeigniter and MySQL. Can
I am trying to insert a few rows into the MySQL table using Codeigniter
Codeigniter has its own Models path, where models extend from CI_Model. I'm using RedBean
I am using CodeIgniter 2.1.0 and MySQL. I want to display a horizontal data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.