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

  • SEARCH
  • Home
  • 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 6229867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:38:47+00:00 2026-05-24T09:38:47+00:00

I am trying to import an SQL dump via PHP. I have the following

  • 0

I am trying to import an SQL dump via PHP. I have the following code.

    @mysql_connect("localhost", "root", "root") or die("Cannot connect to DB!");
    @mysql_select_db("great_database") or die("Cannot select DB!");
    $query = file_get_contents('defaultDatabasePartOne.sql', FILE_USE_INCLUDE_PATH);
    debug($query);
    $result = mysql_query($query);      
    debug($result);

    $error = mysql_error();
    debug($error);

I know it is correctly loading my file, because it debugs $query, which is the file. I removed comments from the file, but it still has line breaks, this wouldn’t be a problem, would it?

I know that this error can have to do with a timeout, but I ran SET GLOBAL wait_timeout =99999999999 and it didn’t change anything so i think that might not be it? I am not experienced in SQL how can I fix this?

Here is the example for @chris:

CREATE TABLE `access_tokens` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `token` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `user_id` int(11) NOT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
  • 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-05-24T09:38:49+00:00Added an answer on May 24, 2026 at 9:38 am

    Found this:

    Heres the function i used to do this operation:
    Thought i’d post it just for those who need it in the future.

    • $url is the path to the sql file
    • $nowhost is dbhost
    • $nowdatabase is db
    • $nowuser is db user
    • $nowpass is db pass

    Code:

    function parse_mysql_dump($url,$nowhost,$nowdatabase,$nowuser,$nowpass){
        $link = mysql_connect($nowhost, $nowuser, $nowpass);
            if (!$link) {
               die('Not connected : ' . mysql_error());
            }
    
            // make foo the current db
            $db_selected = mysql_select_db($nowdatabase, $link);
            if (!$db_selected) {
               die ('Can\'t use foo : ' . mysql_error());
            }
       $file_content = file($url);
       foreach($file_content as $sql_line){
         if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
         //echo $sql_line . '<br>';
           mysql_query($sql_line);
         }
       }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to import an access database to mysql. I have created a
I have a Microsoft Access database query that I'm trying to import into a
I am trying to subclass NSOutlineView. Here is my code: OutlineViewSublcass.h: #import <Cocoa/Cocoa.h> @interface
I am trying to import a dump into two schema in the same oracle
I have a ton Visual FoxPro db files that I am trying to import
I'm trying to import IIS logs into SQL Server 2008. I get this error
I am trying to import CSV file to SQL server database, with no success.
I've been trying to import a table from oracle 10g into SQL Server 2005
I'm trying to import data from a Progress database into a MS SQL 2005
I'm trying to import an 82k+ row table from an access db to SQL

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.