Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:22:41+00:00 2026-06-15T20:22:41+00:00

i have a .sql file which contains the exported code from some database #

  • 0

i have a .sql file which contains the exported code from some database

   # Dump File
    # Database is ported from MS Access
    CREATE DATABASE IF NOT EXISTS `movedb`;
    # Table structure for table 'test_prefixSwitchboard Items'
    DROP TABLE IF EXISTS `test_prefixSwitchboard Items`;
    CREATE TABLE `tbl` (
      `x` INTEGER NOT NULL, 
      `y` INTEGER NOT NULL DEFAULT 0, 
      `z` VARCHAR(255)
    ) ENGINE=innodb DEFAULT CHARSET=utf8;
    SET autocommit=1;
    #
    # Dumping data for table 'Switchboard Items'
    #
    INSERT INTO `tbl` ( `x`, `y`, `z`) VALUES ( '111' , '111' ,'111');
    INSERT INTO `tbl` ( `x`, `y`, `z`) VALUES ( '222' , '2222' ,'222');
    INSERT INTO `tbl` ( `x`, `y`, `z`) VALUES ( '333' , '333' ,'333');

i want to put it’s values into my database , my column names are diferent from .sql file column names so i need to only extract the values i.e

'111' , '111' ,'111'
'222' , '2222' ,'222'
'333' , '333' ,'333'

and there might be some other tables in that file so its important to get this table only .

i usually don’t ask question without providing any code of my own , but i suck at regex stuff and this seems very complected at least to me.

i have to add , someone is going to uupload this file every couple of day . and i want to add some values to current values before inserting them on my database so i’m more comfortable to use regex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:22:42+00:00Added an answer on June 15, 2026 at 8:22 pm

    You can match the VALUES ( portion, then capture the text from then on until you hit ); and the end of the string, like this:

    preg_match_all( '/VALUES\s+\(\s+(.*?)(?=\);\s*$)/', $file, $matches);
    
    foreach( $matches[1] as $match) {
        echo $match;
    }
    

    This will print:

    '111' , '111' ,'111' 
    '222' , '2222' ,'222' 
    '333' , '333' ,'333'
    

    Edit: For table names, you would add the table name to the regex, then churn through the column names since you don’t care about capturing them like this:

    preg_match_all( '/`tbl`.*?VALUES\s+\(\s+(.*?)(?=\);\s*$)/m', $file, $matches);
    

    Where you can change tbl to anything you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file which contains data from a SQL DataSource . I
I have an .sql file which contains some data like first_name, last_name, email etc.
I have a .sql file from a MySQL dump containing tables, definitions and data
Suppose I have a myTest.sql scripts, which contains thousands of create table blahblah statements.
I have a VB web application that reads from a CSV file which contains
I have a sql server 2005 database which contains a user table.. Is it
I have a huge pdf file (20 mb/800 pages) which contains some information. It
I have a file which contains sql statements. Now in this file, I want
I have a sql file which contains over a million insert statements. The official
I have a rather large SQL file which starts with the byte order marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.