473,467 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to skip error msges ?

190 New Member
i have written a script that will insert data into database after readingfrom csv file.But i get a problem when if due to some reason insert statement gets error .The whole uploading process stops.

What i want is that :

When ever insert statement gets error it should't stop,Should continue jumping on next record. and at the end it should me give msg that these many records are not being inserted due to this reason.

how to catch exceptions in php+mysql ?


Pls help
Nov 25 '08 #1
8 3358
Markus
6,050 Recognized Expert Expert
Ok, loop through your queries, then you and IF check to see if the query was successful (queries return TRUE if are successful, else FALSE). Something like the below (pseudo).

Expand|Select|Wrap|Line Numbers
  1. $badQueries = array();
  2.  
  3. foreach($queries as $x => $query)
  4. {
  5.     if ( ! $query )
  6.     {
  7.         // query didn't work :(
  8.         $badQueries[] "$x didn't execute - " . mysql_error();
  9.     }
  10. }
  11.  
Nov 25 '08 #2
Shalini Bhalla
190 New Member
i have a csv file which i need to upload in database using insert statement.

now the thing is that if by chance there is any problem in any insert statement , it gives me error message and stops the whole process.

i don't want to stop the whole process . i want that it should continue and should stop at the eof telling me how many queries were successfull and how many were not.

Is it possible ?
Nov 27 '08 #3
Markus
6,050 Recognized Expert Expert
Shalini Bhalla, it is against the forum guidelines to doulbe post a question. This is your first official warning as you have been here long enough to know the guidelines.

Read the forum guidelines now, to avoid any further warnings.

Moderator.
Nov 27 '08 #4
Shalini Bhalla
190 New Member
but i did't get the ans sir ........sorry for that will not happen again...
Nov 28 '08 #5
Markus
6,050 Recognized Expert Expert
My first post in this thread explains an easy way to do it.
Nov 28 '08 #6
mwasif
802 Recognized Expert Contributor
Shalini,

What you have made so far?
Nov 28 '08 #7
Shalini Bhalla
190 New Member
Actually my requirement was to insert data from one csv file to a database and after printing i wanted my script to print how many inserted , how many were duplicate hence skiped and how many were containing some empty fields hence skiped.

I was stucking at the point where due to some reason insert statement get error and stops the whole uploading,

I wanted to do exception handling for that

But now i have taken this in consideration that my data should not contain any special character , mainly "." or " ' " or ' " ' so that insert statement shouldn't stop . And done it for the time being .....

Now its checking empty fields and duplicate which are not entered in database and counting for empty , duplicate and insert data and printing it .....

But still i want to learn exception handling for it ... any good tutorial site you suggest ....
Dec 1 '08 #8
Markus
6,050 Recognized Expert Expert
Exception handling: google is your friend.

To escape any harmful characters in your query, use mysql_real_escape_string() on your string.
Dec 1 '08 #9

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

Similar topics

1
by: Daniel Loose | last post by:
Hi, a friend was so kind to host my php scripts. but when they use phpmailer (or other PHP mail facilities) to email e.g. to an invalid address, the returning error message appears in *my...
1
by: Peter | last post by:
Hello, I am having trouble processing an XML file that contains an error on one of the nodes. How can I instruct the .NET framework to skip the node and continue when it comes across a node...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
4
by: Andrew | last post by:
Please check the string in "stralertscript ". if ( ds.Tables.Rows.Count == 0 ) { stralertscript = "<script language='javascript'> "+ " function alert() "+ " { "+ " alert ('Testpaper not...
5
by: rod.weir | last post by:
Hello, I have the following code to iterate through each view in a SQL Server and call the "sp_refreshview" command against it. It works great until it finds a view that is damaged, or otherwise...
1
by: Jacob Marble | last post by:
Hello NG- I'm using mysql 5.0.22 as packaged (and updated) with Ubuntu Dapper. I would like to use Innodb, but "show innodb status" says "ERROR 1235 (42000): Cannot call SHOW INNODB STATUS because...
13
by: Alex | last post by:
For example, i have some part of XML file. <AppSettings> <Object ClassVersion="1.0.0.0" Type="AppSettings"> <Fields> <Field Name="App_ID" Type="System.Int32"> <Value> <int>-1</int> </Value>...
2
by: elmar_macek | last post by:
Hi all, i have recently stumbled about a problem: I have implemented a class GeneraBucket, which is superclass for Bucket and PBucket. I need a method in PBucket that returns a pointer to a...
0
by: d-42 | last post by:
You wrote a great deal and there is so much I would have liked to elaborate on but this really de-railed the whole debate. You posted that linq DOES throw an exception if its not ordered, and that...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.