CodeIgniter Forums
Dump big rows using CI return error memory limit - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Dump big rows using CI return error memory limit (/showthread.php?tid=69829)



Dump big rows using CI return error memory limit - plonknimbuzz - 01-22-2018

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Migration extends CI_Controller {
    
    function 
test_ci()
    {
        
ini_set('memory_limit''2048M'); //i even tried -1 (my RAM is 8Gb)
        
$this->db->save_queries FALSE//just make sure save_queries disabled
        
$q $this->db->query("SELECT * FROM mytable"); 
        echo 
$q->num_rows(); 
    }
    
    function 
test_native(){
        
$serverName "****";
        
$connectionInfo = array( "Database"=>"****""UID"=>"****""PWD"=>"****" );
        
$conn sqlsrv_connect$serverName$connectionInfo);
        
$sql "SELECT * FROM mytable";
        
$stmt sqlsrv_query$conn$sql , [], ["Scrollable" => SQLSRV_CURSOR_KEYSET] );
        echo 
sqlsrv_num_rows$stmt );
    }
    


my database.php
PHP Code:
$active_group 'default';
$query_builder TRUE;

$db['default'] = array(
    
'dsn'    => '',
    
'hostname' => '***',
    
'username' => '***',
    
'password' => '***',
    
'database' => '***',
    
'dbdriver' => 'sqlsrv',
    
'dbprefix' => '',
    
'pconnect' => FALSE,
    
'db_debug' => (ENVIRONMENT !== 'production'),
    
'cache_on' => FALSE,
    
'cachedir' => '',
    
'char_set' => 'utf8',
    
'dbcollat' => 'utf8_general_ci',
    
'swap_pre' => '',
    
'encrypt' => FALSE,
    
'compress' => FALSE,
    
'stricton' => FALSE,
    
'failover' => array(),
    
'save_queries' => FALSE //disabled save_queries
); 

i want to dump all my rows (180k++ rows) for several purpose (like migration, etc). But i always get memory_limit error. 

So i create 2 method to compared my problem:

test_ci = fatal error memory_limit blabla
test_native = 180k++

NOTE:
Quote:1. in this demo i just try to count rows to simplify the demo code. But in the real case i have have complex script to parse the result.
2. i can hack this using Limit clause. But i just want to know how to do this using CI.


i tried to googling this for an hour but still not get any luck.
did i miss something?


RE: Dump big rows using CI return error memory limit - InsiteFX - 01-23-2018

You would need to dump it out with phpMyAdmin.

You could then read and write out using CodeIgniter in chunks.


RE: Dump big rows using CI return error memory limit - php_rocs - 01-23-2018

While I agree with InsiteFX, my question is...did you check the PHP and CI error logs to see if you could get more information?