Convert SQL to PHP Array Online

Paste a SQL table below, edit it if you need to, and get PHP Array back. The conversion runs in your browser, so nothing is uploaded, there is no size limit and there is no signup.

From

The only part of this site that uses a server. The address is sent to it so the page can be fetched, because a browser is not allowed to fetch someone else's page itself. Your own files are never involved.

Nothing here is uploaded. The parsing happens on this page.
Edit
Paste or upload something above and it will appear here.
ToDataMarkupDocumentsCodeSchemasImages

The output will appear here once there is a table to convert.

What SQL is

SQL here means the statements that move a table into a database: INSERT INTO with a VALUES list, and optionally the CREATE TABLE that defines the columns.

Anyone seeding a database, moving a spreadsheet into an application, or writing a migration.

What PHP Array is

A PHP array literal: an outer array of rows, each an associative array keyed by column name.

PHP applications that need a lookup table in code rather than in a database.

What changes when you convert SQL to PHP Array

Column names come from the INSERT column list, or from a CREATE TABLE if one is present. Quoted strings are unquoted, doubled quotes are collapsed, and NULL becomes an empty cell.

Values are single-quoted with backslashes and quotes escaped, so the output can be pasted into a file as is.

What carries over from SQL to PHP Array

SQL records 2 things about a table that PHP has no way to hold.

PHP has no header row. The column names are repeated as keys on every record instead, which is why the result is bigger on disk than the table it came from.

SQL can be read one record at a time. PHP has to be complete before it means anything, so the whole table is held in memory while it is written and a file that gets cut off part way through is not partly usable - it is unusable.

Both formats record types, so numbers, booleans and nulls survive as themselves rather than as text.

The identifier 007 comes out of the PHP Array as 007. Reading it as a number would have made it 7, and an id that changes value is worse than one that stays text.

The role "Analyst, data" survives with its comma, in one cell rather than split across two. That is the first thing to check in any converted table, and the usual place a PHP Array file goes wrong.

The quotes around Jonah "Jo" Pryce are left as a plain quote character in the PHP Array.

A worked example

Three rows of staff data, with an identifier that has a leading zero, a value containing a comma, a value containing quotes and one blank cell. Those are the four places formats disagree, so they are the four places to look.

SQL in
INSERT INTO `staff` (`id`, `name`, `role`, `started`, `hours`) VALUES
  ('007', 'Halima Yusuf', 'Analyst, data', '2024-03-15', '38.5'),
  ('012', 'Jonah "Jo" Pryce', 'Engineer', '2025-11-02', NULL),
  ('104', 'Wei Chen', 'Manager', '2023-06-30', '40');
PHP Array out
$staff = [
  ['id' => '007', 'name' => 'Halima Yusuf', 'role' => 'Analyst, data', 'started' => '2024-03-15', 'hours' => '38.5'],
  ['id' => '012', 'name' => 'Jonah "Jo" Pryce', 'role' => 'Engineer', 'started' => '2025-11-02', 'hours' => ''],
  ['id' => '104', 'name' => 'Wei Chen', 'role' => 'Manager', 'started' => '2023-06-30', 'hours' => '40'],
];

Questions

How do I convert SQL to PHP Array?

Paste your SQL into the box above or drop the file onto it. Check the table in the grid, then copy or download the PHP Array from the output panel. It takes one step and the data never leaves your browser.

Are the generated INSERT statements safe to run?

Quotes in your data are escaped, so the statements are syntactically correct. They are not parameterised, which is fine for a one-off import you are running yourself and not fine as a pattern for application code that takes user input.

Is there a limit on file size?

No. The work happens on your own machine, so the limit is your machine's memory rather than an upload cap. A file with tens of thousands of rows converts in a second or two.

Is my data uploaded anywhere?

No. The parsing and generating are done by JavaScript running on this page. You can watch the network tab while you convert and see that nothing is sent.

Related conversions