Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

PHP and Excel

hello everyone,

I am doing my first attempt at using PHP with excel.  I need to import all the values from my excel worksheet into MySQL.  Does anyone have any clue how to do so?  I have checked alot of sites from my searches on Google, but i cant figure it out.  

Any info you could give me would be greatly appreciated.

- Dan
  • 3
1 Solution
The only way PHP can read Excel files is if it's running on Windows and through ODBC. On Linux you need to save your Excel worksheets as CSV/tab delimited.

If you only need to do it once, you might want to try out this product: http://www.sqlmanager.net/en/products/mysql/dataimport
Richard QuadlingSenior Software DeverloperCommented:
I use the very good Zakkis Excel reader class.

There is a good example with the class showing you just how to do what you want.

Richard QuadlingSenior Software DeverloperCommented:
I would recommend saving Excel in a CSV format.

PHPMYADMIN will allow direct imports from this!
Richard QuadlingSenior Software DeverloperCommented:
I would STRONGLY recommend NOT using CSV files.

They are VERY easy to break.

Think of this.

Your columns are separated by a comma.
Your text columns are surrounded by single or double quotes (pick 1).
Your records are terminated by a CR/LF (one or both, depending upon OS).

Now say you have a description of ...

Black, nylon rope 12'6" long.


The , will be ok as it will be within single or double quotes.

Try double

"Black, nylon rope 12'6" long."


"Black, nylon rope 12'6"

the [space]long. is lost.

Single quotes.

'Black, nylon rope 12'6" long.'

Now we add 6" to the lost part.

CSV is unstructed data.

If you intend to use a plain text file, you need to do 2 thing.

Use a column separator that cannot appear as part of the data.
Use a row separator that cannot appear as part of the data.

In most cases, CSV files have no support for multiple lines of text, when the text contains the same row terminator. On windows, text lines are terminated with CR/LF. If I have multiple lines of text in a cell, then CR/LF will be on each line.

You may not think any of this applies to you. But are you importing people's surnames. I work with a family of O'Connells and we make products 385/80R22.5".

Using a CSV file would fail for us.

In my nearly 20 years of software development, I would say the CSV file has caused more problems with customers data than any virus/worm/hack! At least you know you have to restore all the data after a virus! But when the CSV importer (and there are a LOT of these) says "Hey! Thanks for the data! Yummy!" and it all gets screwed up and you don't know until weeks/months later ... then you REALLY know the feeling of panic/horror!

So. Please do NOT use a CSV file. For your own personal well-being.


Please, please, please!


Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now