How does phpmyadmin writes a table in a pdf file? - mysql

There is an export option in phpmyadmin which can be used to write a database table in a pdf file. How does phpmyadmin do that? Basically, what I am asking is if I want to write a table in pdf using command prompt then how can it be done? Is php required somehow to do it or it can be done purely using MySQL command prompt?

You can store the results of a query to a text file like this:
SELECT * from someTable
INTO OUTFILE 'file.txt'
(See: http://www.tech-recipes.com/rx/1475/save-mysql-query-results-into-a-text-or-csv-file/)
From there, you can use enscript and ps2pdf to convert the text to a pdf
enscript file.txt --output=- | ps2pdf - > file.pdf
(See: a light solution to convert text to pdf in Linux)
That's one possible way to do it.

There is no capability within SQL to write to a PDF. phpMyadmin uses php to do this. It's open source so you can look at the code if you want
However, rather than copying the method used by phpMyadmin, if you want the capability to do this, I recommend looking into tcpdf or fpdf, which are php libraries designed to handle this. Take a look here: http://sourceforge.net/projects/tcpdf/

Related

Getting Minizinc output as .txt from IDE

Imagine I ran a .mzn with .dzn and got an output in IDE as follows:
Supplier01,100,100,100,100,100,100,100,100,100,100,100,100
Supplier02,200,200,200,200,200,200,200,200,200,200,200,200
Supplier03,40,49,359,834,1067,1377,334,516,761,1001,1251,1583
Supplier04,500,500,500,500,500,500,500,500,500,500,500,500
Supplier05,161,200,200,200,200,200,200,200,200,200,200,200
Supplier06,500,500,500,500,500,500,500,500,500,500,500,500
----------
==========
Is there any way that I can generate this output in a .txt or .csv file in a preferred location on my computer? I know that we can perform this in command prompt, but is there any way we can do using the IDE it self?
The MiniZinc IDE currently does not include functionality to export solutions for other applications.
The current expectation is that if you want to integrate MiniZinc with other applications that you would use something like MiniZinc Python, iMiniZinc, or the command line tools, to facilitate the connection. In your case using MiniZinc Python or iMiniZinc might be a good solution since Python can generate csv files using the csv module. If you want to see and interact with the solution as well as outputting the csv file, then iMiniZinc can provide the right tooling in Jupyter Notebook to do both.
If you are very happy with the MiniZinc IDE and you want to continue using it, then the other option would to just minimize the inconvenience. Your output statement already provides the solution in csv style. So the only remaining part is making the file. The MiniZinc IDE can open .csv files. So my suggestion would in this case be to create an empty .csv file, open it in the IDE. Once you get the solution from your instance in the output window, then you copy directly into the file.

MySQL Workbench 6.1 - Error importing recordset

I'm going to be getting a new computer soon and I don't want to lose all of the data I have entered in my tables, so I decided to test out the feature that allows you to export and import CSV files. I exported a table successfully (data was transferred to Microsoft Excel in CSV file), but when I opened the file in Microsoft Excel and added a few rows and tried to import it back in to MySQL Workbench, I got the following error:
"Error importing recordset
error calling Python module function
SQLIDEUtils.importRecordsetDataFromFile"
I've searched all over for info on this, but can't find any solutions. Does anyone know what I'm doing wrong?
In Workbench, open a MySQL connection and then navigate to [Server] --> [Data Export]. There are several backup options here, including saving the data as an individual file or folder. Choose the databases you want to export, and then click [Start Export].
If you ever prefer using Excel for editing and such, then use the MySQL for Excel plugin to access MySQL databases from within Excel. However, I don't think you need it here.
To export your mySQL data, use mysqldump, which will create all the schema for you.
Excel probably added some stuff to your file and now mySQL can't understand it. The best way to find out is by comparing the files before and after the change.
That error indicates a format problem. If the file is small enough, try opening it in wordpad (or the mac equivalent) and see if there's any difference in the formatting? Could be that the delimiting got a little messed up (this can happen especially with end of row markers in MySQL, I've noticed, it can also happen in mac to pc handoffs). If all else fails you could try exporting using a different format and see if that makes a difference (maybe tsv) when you add new rows.
Another reason can be the line endings used. Depending on the system and editor used to work with the cvs file it the line endings might get changed. For me mysql supported UNIX line endings. And in the editor the line ending had been set to MAC OS 9 since I was using a MAC.
Changing it to UNIX line ending worked.
I found that it might be due to a wrong encoding of the input file.
Using Notepad++ for example (or another similar editor) you need to change file encoding to UTF-8.

Download MySQL table as a spreadsheet

How do you download an sql table as an Excel spreadsheet?
Any help would be appreciated.
Thanks
Use a SELECT ... INTO OUTFILE ... statement to write a CSV file or a tab-delimited file that you can open directly in Excel.
Navicat, MySQL Workbench and phpMyAdmin would all work if you want to create the spreadsheet yourself.
To allow users to download spreadsheets from a website, you can use a library. Some good options are:
IIS:
EPPlus http://epplus.codeplex.com/ or NPOI http://npoi.codeplex.com/
Apache:
PHP Excel (http://phpexcel.codeplex.com/) or Apache POI (http://poi.apache.org/)
Use phpMyAdmin, it has option of exporting thata to multiple formats:
csv,scv for excel, json, doc, latex, wiki table, odf, pdf, sql
Use a database client like Navicat.

Ways to export Tables/Views from mySQL Database to printer friendly format (other than phpMyAdmin)

I've created a bunch of views in a database and I'd like to export them to pdf. However phpmyadmin lets me only put a title on each page and it's very limited to how i can layout the output.
does anybody have some recommendations of software/scripts they used?
tcpdf is a PHP class for generating pdf documents. They have many example scripts.
There are a fantastillion ways to do this, some ideas:
export csv, import it to your favorite spreadsheet editor, format it, get the pdf using a pdf printer.
export xml, process it using xsl-fo to produce the output you want ( hacking required, fun )
export html ( should work? ), put a css on top optimized for print layout, pdf-printer.
Usually, I write up a script to pull info from a database, then generate a .csv, attach it to an email and send it on its way. Most scripts with support for mySQL can do that and they also go as far as generate a .pdf file with the appropriate formatting (in my case, I use Ruby, so I could have used Prawn to generate a PDF - I just choose not to as of this time).

iSeries Export to CSV

Is there an iSeries command to export the data in a table to CSV format?
I know about the Windows utilities, but since this needs to be run automatically I need to run this from a CL program.
You can use CPYTOIMPF and specify the TOSTMF option to place a CSV file on the IFS.
Example:
CPYTOIMPF FROMFILE(DBFILE) TOSTMF('/outputfile.csv') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)
If you want the data to be downloaded directly to a PC, you can use the "Data Transfer from iSeries" function of IBM iSeries Client Access to create a .CSV file. In the file output details dialog, set the file type to Comma Separated Variable (CSV).
You can save the transfer description to be reused later.
You could use a trigger. The iSeries Client Access software wont do since that is a windows application, what I understand is that you need the data to be exported each time that the file is written. Check this link to know more about triggers.
You are going to need FTP to perform that action.
If your iSeries shop uses ZMOD/FTP your shortest solution is a few lines of code away -- 3 lines to be exact -- the three lines are to Start FTP, Put DBF, and finally, End FTP.
IF you don't use ZMOD/FTP:
- You could use native FTP/400 to accomplish what you need to do, but it is quite involved!!!
- you may probably need to use an RPGLE program to parse, format, and move, data into a "flatfile", then use native FTP/400 to FTP the file out
- and yes, a CL will need as a wrapper!
You can do it all in one very simple CL program:
CPYTOIMPF the file TOSTMF -> the cvs file will be in the IFS
FTP the file elsewhere (to a server or a PC)
It works like a charm