473,800 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop of queries fails

3 New Member
Hello everyone. I am loading a text file into a MySQL table on my local machine. I am using the code below. The process stops at approx 70,000 records and does not finish. But, there is no error - no "something went wrong" or error in the mysql log. If I run the file for 50,000 records then run the file again, the table will have the full 100,000 and finish properly both times. If I run the file once using the loop to run 2 rounds of 50,000 the table will only have 65,000 records and will not finish. Is it possible there is a limit on the number of queries that can run in one session? How else can I run the full file of 360,000 records?

<?php
$files_root = "path";

$file = $files_root."sa mple.csv";
$sep = "\",\"";

$fp = fopen($file,"r" );
$chunklen = 0;
$chunk[0] = fgets($fp,2048) ;
$headers = explode($sep, $chunk[0]);
$headers = str_replace("\" ", "", $headers);
$headers = str_replace("'" , "", $headers);
$numheaders = count($headers) ;
echo $numheaders;
echo "<br />";
// Check Valid FILE
if ($headers[0] != "text") {
return false;
exit;
}
$chunklen=strle n($chunk[0]);
echo $chunklen."<br />";

echo "Now data <br />";

$host = "localhost" ;
$user = "motta";
$pass = "xxxxxx";
$dbname = "mottst";

$i = 0;
while ($i < 2) {
$j = 0;
while ($j < 50000) {

$conn = mysql_connect($ host,$user,$pas s);
// echo $conn;
mysql_select_db ($dbname,$conn) ;
$chunk[0] = fgets($fp,2048) ;
$fields = explode($sep, $chunk[0]);
$fields = str_replace("\" ", "", $fields);
$fields = str_replace("'" , "", $fields);

$query_start = "ref_id,vin,veh icle_code,make, model,body_styl e,model_year,v_ features,price, max_mileage,ext _color,long_des cription,is_cer tified,transmis sion,doors,engi ne_size,comp_po stcode,dealer_u sername";
$query_val = "'{$fields[0]}','{$fields[1]}','{$fields[2]}','{$fields[3]}','{$fields[4]}','{$fields[5]}','{$fields[6]}','{$fields[7]}','{$fields[8]}','{$fields[9]}','{$fields[10]}','{$fields[11]}','{$fields[12]}','{$fields[13]}','{$fields[16]}','{$fields[18]}','{$fields[20]}','{$fields[23]}'";


$query = "insert into temp_tbl(" . $query_start . ") values (" . $query_val . ")";
if (mysql_query($q uery, $conn)) {
} else {
echo "something went wrong at ".$j;
}

$j++;
} //end of inner while $j


mysql_close($co nn);

$i++;

} // end of outer while

fclose($fp);


?>
Dec 18 '07 #1
1 1082
allanr
3 New Member
Issue is Solved. Received the answer through another forum. If I put set_time_limit( 0) in the outer loop, the script finishes. The script was taking too long to run. Thank you to all who read this post.
Dec 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

47
12346
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) { int result = 0; for(int i = 1;i <=iterations;i++) { result += i;
4
3258
by: Paul | last post by:
I have run into a strange problem with a site I am working on. My SELECT queries work fine, but I just tried to add an UPDATE statement and it fails. A test showed that INSERT fails also. I created a new table just for testing called "blah" and it had the same results. My statements: "UPDATE GiftCerts SET Paid=1 WHERE CertSerial='2005-0001'" and "INSERT INTO blah (test) VALUES ('something')"
3
21894
by: KS | last post by:
I am passing the following three queries in a string in VS.NET C# class string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM TABLEC;"; OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my connection object) DataSet ds = new DataSet; thisAdapter.Fill(ds); If the second query fails, the third query doesn't get executed. If the
3
4172
by: Vincenzino | last post by:
Hi, I have some problem in using SQL3 recursive queries on DB2 database system (8.1 and 8.2 UDB). I need to compute the transitive closure of a (possibly) ciclic graph using SQL3 on DB2. I MUST use pure SQL3 and I cannot use cursors, indexes and the like. The graph is represented by a set of arcs with the table "arc" having two attributes "a1" and "a2" for source and target nodes resp. The SQL3 query I'm using is the following:
5
1823
by: chrisc | last post by:
Hello, Hope this is the right place for this... I am creating a testing database for components as they come off a production line. My reports need to select faults that are found, as well as pass or fails dependent on a batch number.
0
1510
by: Mark Harrison | last post by:
HOWTO: Integrating Posgresql queries into an event loop. Mark Harrison mh@pixar.com May 27, 2004 Problem ------- The commonly used postgresql APIs will block until completed.
2
2212
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= | last post by:
Hi there guys, My doubt is related to PHP and MySQL usage, and it's related to check if performed queries are performed with success, since we know that: Each time we perform an sql query, we can check if it was performed with success like this:
16
3524
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.