How to import .sqlite file to sqlite3 - php

I'm trying to import .sqlite file to sqlite3 im using windows 8 pc,
It's throwing an error of
expected 5 rows found 1-rest filled with null
even my table columns are fine.
can anyone please help me.
thank you in advance.

I think you can try this method. So you don't have to import/export via third-party files such as csv or any additional software. I plan to do this method to periodically copy aquired data in a RAMDRIVE-placed database to the SD-Card. Of course sqlite3 must be able to load your database in your case.
ATTACH DATABASE 'foo.sqlite' AS 'foo';
.databases
INSERT OR REPLACE INTO 'main.mytable' SELECT * FROM 'foo.mytable';
DETACH DATABASE 'foo';
.databases
check here for ATTACH syntax and here for more INSERT variations.

What you can do is use a third party tool called SQLite Database Browser (http://sourceforge.net/projects/sqlitebrowser).
Using the sqlite browser, open your database in old format (.sqlite) and then click File -> Export -> Database to SQL file.
Now, close the database. Create a new database using SQLite Browser (it automatically generates the database in the new SQLite3 format). Once a database is created, use the File -> Import -> Database to SQL file into the new database in SQLite3 format.

You use the PHP sqlite API to use an .sqlite database.
See http://php.net/manual/en/book.sqlite.php
In general you supply the path to your .sqlite file in the sqlite_open() call, see for an example the manual page of sqlite_open:
http://www.php.net/manual/en/function.sqlite-open.php

Related

How to import all databases at a time in wamp

I export whole databases sql file from localhost wamp. Now I want to import all databases and table by importing that one sql file. But I get sql error...database error with name...and following error. Plz give me solution for this.
MySQL said:
#1046 - No database was selected
First select your database, then do the import. You can modify your sql file with a use databasename; to select a database for you during import
1046 - No database was selected
This error suggests that when you dumped all these database the resulting .sql file does not contain the required use databasename; between each database restore.
You will have to edit the .sql file and add a use databasename; statement for each database, just before the restore changes the database it is restoring.

How can I read and import .txt file into database?

I have a .txt file on our webserver which gets updated and replaced by the client's third party property software.
Does anyone have a script (PHP/MySQL) where I can read this file and import it into a table in my database? Ideally something using codeigniter, but standard PHP will work just fine too.
It is in this format:
"BranchID","PropertyID","PropertyName","Street","DisplayStreet","Postcode","PricePrefix","Price","Bedrooms","Receptions","Bathrooms","ParkingSpaces","Numeric5","Numeric6","Numeric7","Numeric8","Numeric9","AREA","TYPE","FURNISHED","CHILDREN","SMOKING","PETS","GARDEN","DSS","PARKING","cFacility1","cFacility2","cFacility3","cFacility4","cFacility5","cFacility6","cFacility7","cFacility8","cFacility9","cFacility10","Tenure","ShortDescription","MainDescription","AvailabilityCode","AvailabilityDate","FullAddress","PricePrefixPos"
My field names match these headers exactly.
You can use the MYSQL LOAD DATA INFILE directly, see MySQL Reference
This will save come scripting time and will be much faster than importing it via a PHP script.
You may also parse it with PHP.
It looks like a csv.
I would use fgetcsv() to parse the file.

access excel programmatically, run a ODBC query, save data, do vlookups

I am looking for a way to automate an entire process that uses Excel & ODBC queries. I know that Excel can use to a ODBC driver to run queries against a Mysql database. But I need this query to be triggered programmatically.
The individual steps the program or script should be able to do are:
1. Open Excel file
2. Run Mysql query (query will not change but the values the query hits the database for will come from the excel file)
3. Save results of the query to the Excel file as a sheet
4. Use the results to do vlookups against another sheet in the same excel file
5. save results of vlookups and close the file
Flexible on the language or any add-ons necessary. Anything out there that would help? I am looking to run this both on windows and mac.
What you want to do is probably possible using COM (Python tutorial). It will be messy, hard to code and hard to debug. And no way it'll work on a mac.
Instead, if I was you I would try and take the problem out of excel. For instance in Python, I would first directly access mysql. I would then parse my second xls file using xlrd. With the results of the mysql query and the parsed xls file both in Python data structures, replicating the behaviour of VLOOKUP is easy. I would then write the results to my output xls file using xlwt.

how to converted the excel file into sql file

hi i want to converted my excel file into sql file can any one know what should i do for converting? i dont know how to converted.
thanks
Use sql convertor from below link
http://www.sqlconverter.com/
OR
You need to convert the .xls file to .csv(comma seperated file) and then use the loader to load the data if you want to load the .xls data to database.
Try Navicat products.
I used Navicat for MySQL for example and it provides great flexibility in Importing Excel sheets in Mysql tables.
From there you can run any type of SQL query
Here is web application tool that allows fast Excel to MySQL conversion.
Excel data does not have a Schema by default and this tool allows you to define it interactively with the help of a wizard.
Input
An Excel (xls / xlsx) data file, whose format is given in the documentation they provide.
Output
A .sql export file (which can be imported into a MySQL database) is available for download after the conversion is done. (And it works pretty fast)
The other option is to export to CSV first. Excel can export to CSV and then MySQL can import CSV via LOAD command or PHPMyAdmin. The schema should be defined before. Its a little longer process.

How to convert excel file into mysql database? [duplicate]

This question already has answers here:
How to import an excel file in to a MySQL database
(15 answers)
Closed 9 years ago.
my boss wants me to create a mysql database for an existing excel file. I was wondering if there are any ways to do convert or import excel file? I have searched google but didn't find anything useful. I appreciate for any reply....Thanks.
Save as CSV
Use a COPY sql statement
Profit
If you have a web server up and running with PHP support, I highly recommend phpMyAdmin.
Configure it to connect to MySQL
Create the Database and table
Click the import tab and you can import a CSV.
If this is a simple one-time import this probably isn't worth the effort. If, on the other hand, you will ever have to work with MySQL again, you will never regret the time to install and configure phpMyAdmin.
PHPMyAdmin can import CSV files, as well as Excel files (though I've never tried it)
First you need to create your datebase, and add a table. There must be as many fields in that table as there are columns in your Excel document (yes, I know you know)
Then select that database and table in phpmyadmin and use the "Import" tab.
I wrote a tool that will let you do sql queries against a csv file. The output is saved as a csv as well. Maybe you will find it useful.
http://whitlock.ath.cx/EasyCSV/
From Excel, export the sheet as a text file. In MySQL, use LOAD DATA INFILE to import the text file.
easiest way to do it would be this:
insert into Table (col 1,col 2,col 3...col n) values (val1,...valn);
basically:
do 2 for loops in your excel:
dim i,j
dim sqlString,sqlBase
sqlString=""
sqlBase="insert into yourTable (col1....coln) values ("
for i=1 to myRowVariable
sqlString=""
for j=1 to myColVariable
if j=myColVariable then
sqlString=sqlString & Cells(i,j).value & ");"
else if j=1 then
sqlString=sqlBase & sqlString & ","
else
sqlString=sqlString & Cells(i,j).value & ","
end if
Next j
Next i
'write sqlString into a txt or something
this will do what you need in a bootstrap but fast and very intuitive way.
You can use an ODBC driver to "mount" an Excel file as database and then make SQL queries to it. All you need then, is a simple migration tool, to copy the tables to another databases system.
I believe there's even an mysqldump-like tool for ODBC driven databases.
A low tech solution would be to use the concatenation function in excel to convert the data into a series of insert statements and then copy and paste them into mysql query analyzer or whatever client you are using.

Categories