Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 10-11-2016, 11:37 PM
shibli2700 shibli2700 is offline
Contributing Member
 
Join Date: 09-15-16
Location: Mumbai
Posts: 72
iTrader: 0 / 0%
How to import .sql file using php

I want a php script to import a .sql file, can anyone help me
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 10-12-2016, 01:10 AM
saikumar011's Avatar
saikumar011 saikumar011 is offline
Banned
 
Join Date: 09-29-16
Location: chennai
Posts: 81
iTrader: 0 / 0%
Both are different i think you can't access if you want to access go for cpanel there you can find sql tool code there.
 
Reply With Quote
  #3  
Old 10-12-2016, 04:55 AM
shibli2700 shibli2700 is offline
Contributing Member
 
Join Date: 09-15-16
Location: Mumbai
Posts: 72
iTrader: 0 / 0%
Quote:
Originally Posted by saikumar011 View Post
Both are different i think you can't access if you want to access go for cpanel there you can find sql tool code there.
Can you please explain a little more
 
Reply With Quote
  #4  
Old 10-12-2016, 05:35 AM
ScriptMan's Avatar
ScriptMan ScriptMan is online now
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 14,015
iTrader: 4 / 100%
Don't reinvent the wheel. Use some free tools that are out there.

Contrary to a popular misconception phpmyadmin does not require cPanel to work. It is free and not hard to install on a vps. If you already have a control panel sgl import is in there somewhere.

read a bit: http://docs.phpmyadmin.net/en/latest/setup.html
 
Reply With Quote
  #5  
Old 10-15-2016, 12:40 PM
d4jk4 d4jk4 is offline
Junior Member
 
Join Date: 10-15-16
Posts: 7
iTrader: 0 / 0%
1, use phpmyadmin
2, write your own script:

PHP Code:
$res shell_exec('mysql -u username -pyour_password db_name < file.sql'); 
Enjoy xD
 
Reply With Quote
  #6  
Old 11-27-2016, 06:58 AM
netcode netcode is offline
Junior Member
 
Join Date: 11-27-16
Posts: 30
iTrader: 0 / 0%
Quote:
Originally Posted by d4jk4 View Post
1, use phpmyadmin
2, write your own script:

PHP Code:
$res shell_exec('mysql -u username -pyour_password db_name < file.sql'); 
Enjoy xD
Any other way rather than use shell_exec? In my opinion shell_exec is too dangerous to use in public area.
 
Reply With Quote
  #7  
Old 11-27-2016, 07:06 AM
Woomeister's Avatar
Woomeister Woomeister is offline
Contributing Member
 
Join Date: 11-10-16
Location: Gloucestershire
Posts: 1,262
iTrader: 0 / 0%
Quote:
Originally Posted by netcode View Post
Any other way rather than use shell_exec? In my opinion shell_exec is too dangerous to use in public area.
It's better to explain your posts.

Why is it too dangerous in your opinion?
 
Reply With Quote
  #8  
Old 11-27-2016, 07:51 AM
netcode netcode is offline
Junior Member
 
Join Date: 11-27-16
Posts: 30
iTrader: 0 / 0%
Quote:
Originally Posted by Woomeister View Post
It's better to explain your posts.

Why is it too dangerous in your opinion?
The exec, shell_exec and system commands are used to run shell commands from PHP. These commands pose a very strong security risk. For example, you might run a command constructed from a form that a user submitted. The user could enter shell commands in the form which would then execute when you run the exec, or shell_exec commands!

In local system, it wont give you potential threat. But if you used in public, and you dont know to secure it, it will give you potential threat.

But once again, it depends on your system administrator.
 
Reply With Quote
  #9  
Old 11-27-2016, 08:18 AM
snakeair snakeair is offline
Super Moderator - Rest in Peace 2018
 
Join Date: 12-31-07
Location: Medford, NJ
Posts: 54,771
iTrader: 3 / 100%
Thanks NetCode.

On this forum we like for members to get into details so anyone reading a reply will learn something new or if they found this topic in the search engines, they will certainly be educated and might even join the forum because of that.

 
Reply With Quote
  #10  
Old 11-27-2016, 11:51 PM
iwebguy iwebguy is offline
Banned
 
Join Date: 11-27-16
Posts: 30
iTrader: 0 / 0%
Try this code ..........
PHP Code:
<?php
 
// OPEN CONNECTION...
$path $_SERVER['DOCUMENT_ROOT'];
$sql_filename 'test.sql';
$sql_contents file_get_contents($path.$sql_filename);
$sql_contents explode(";"$sql_contents);
$connection mysql_connect($server$username$password) or die(mysql_error());
mysql_select_db($name$connection) or die(mysql_error());
foreach(
$sql_contents as $query){
 
$result mysql_query($query);
 if (!
$result)
echo 
"Error on import of ".$query;
}
?>
 
Reply With Quote
  #11  
Old 01-06-2017, 11:29 AM
Roy1985's Avatar
Roy1985 Roy1985 is offline
Contributing Member
 
Join Date: 01-05-17
Posts: 53
iTrader: 0 / 0%
@iwebguy - you code might fail if some data has ; in it for example:

update table set data="data;data1" where column=1;

Last edited by Roy1985; 01-06-2017 at 11:32 AM. Reason: adding details
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to get file full path in Firefox using file browse dialog stephen001 Coding Forum 0 11-27-2014 06:38 AM
My Word file found error message as This file is not a recognized format. alinaalloy Tech Talk 2 09-18-2013 07:31 AM
Cant change ftp port, chkserv.d/ftpd file always back using original file basketmen Coding Forum 0 02-23-2012 08:55 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 11:13 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC