Delphi For PHP Forums    


Go Back   Delphi-PHP Forums > Programming > Database Integration
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

Database Integration How to use MySql, PostgreSQL, MS SQL, Oracle, and most other databases with PHP.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 30th June 2009, 17:53
D4PHP Enthusiast
 
Join Date: Apr 2007
Location: Milano
Posts: 182
goitalia is on a distinguished road
Default Mass insert

Hi,
sure that i lost something. But when i want insert say 5000 record in a table all is stopped after 2800~2850 record, i try to encapsulate the insert loop between try catch but no message the page is blank that's all.
How can i solve this kind of problem?
PHP Code:
 try {

               
$this->Query1->SQL "INSERT INTO table  (
                                    v1,
                                    v2,
                                    codice_1,
                                    codice_2,
                                    codice_3,
                                    codice_4,
                                    completato) VALUES ('"
.
                                    
$v1."','".
                                    
$v2."','".
                                    
$c1."','".
                                    
$c2."','".
                                    
$c3."','".
                                    
$c4."','".
                                    
$completato."')";
               
$this->Query1->refresh(); 
No errors only stop to run.

Many thank's for help.
Paolo.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 30th June 2009, 22:43
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,480
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

It is probably timing out - see
How avoid "Maximum execution time..."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 1st July 2009, 01:16
D4PHP Enthusiast
 
Join Date: Apr 2007
Location: Milano
Posts: 182
goitalia is on a distinguished road
Default Found this solution.

Hi,
as usual 405hp is always the best.
at Welcome to the PHP Classes Repository - PHP Classes
i found this class
PHP Code:
<?php
/*
#####################################################################
# File Name : multipleInsert.inc
# Author : Alok Mohanty
# Last Modify : May 28,2003
# License : GPL
# Contact Info
# E-Mail : alok_r_mohanty@yahoo.com
######################################################################
*/
/*
This class is used for inserting multiple rows in a single query.
*/

class multiInsert
{
var 
$table;
var 
$fields;
var 
$data;

    function 
multiInsert($v_table,$v_fields,$v_data)
    {
    
$this->table $v_table;
    
$this->fields $v_fields;
    
$this->data $v_data;
    }

    function 
generateQuery()
    {
       for(
$i=0;$i<count($this->data);$i++)
       {
          
$query_arr[] = ' (\''.implode ("','"$this->data[$i]).'\') ';
       }
    return 
"INSERT INTO ".$this->table."(".implode (","$this->fields).") VALUES ".implode (",",$query_arr);
    }
}
?>
so the loop for insert begin:
PHP Code:
if ($rec_count == 0) {

       for (
$n $n <= $max $n++){
           
$c1 GUID();
           for (
$k $k $max_arr$k++) {
               
$j = ($n-1)*$max_arr+$k;
               
$t $arr[$j];
               
$a $values[$t];
               
$v1 $a[0];
               
$v2 $a[1];
               
$data_arr[$j][] = $v1;
               
$data_arr[$j][] = $v2;
               
$data_arr[$j][] = $c1;
               
$data_arr[$j][] = $c2;
               
$data_arr[$j][] = $c3;
               
$data_arr[$j][] = $c4;
               
$data_arr[$j][] = $c5;
               }
           }



       
$dbname $this->dboutlet4you1->DatabaseName ;             // MYSQL DataBase Name
       
$dbhost $this->dboutlet4you1->Host;        // MYSQL Host Name
       
$dbuser $this->dboutlet4you1->UserName;             // User Name
       
$dbpwd $this->dboutlet4you1->UserPassword ;                 // Password

       
$link mysql_connect($dbhost$dbuser$dbpwd) or die ("unable to connect");
       
mysql_select_db($dbname,$link)or die("could not select database") ;

       
$table_desn 'dest_table';     // Destination Table
       
$field_arr_desn = Array( v1,
                                        
v2,
                                        
c1,
                                        
c2,
                                        
c3,
                                        
c4,
                                        
c5);

       
$MI = new multiInsert($table_desn,$field_arr_desn,$data_arr);
       
$requiredQuery $MI->generateQuery();

       
mysql_query($requiredQuery) or die(mysql_error()); 
and now it work perfect and very fast.
Many thank for the help.
Have a good day.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 04:51.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use