driveflexfuel
New Member
- Messages
- 159
- Reaction score
- 0
- Points
- 0
I have an SQL file that is over 125 meg and I am unable to upload it using phpmyadmin. I was wondering if someone would happen to have a decent php script to include a sql file.
I tried using this code without any luck.
If anyone has any suggestions please help me out
Edit:
I found this script it works like a dream. Thought many of you would like to see it.
I tried using this code without any luck.
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);
}
}
}
Edit:
I found this script it works like a dream. Thought many of you would like to see it.
Code:
<?php
$sqlFileToExecute = 'ip_info.sql'; //sql file to open
$con = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_name, $con);
if ($con !== false){
// Load and explode the sql file
$f = fopen($sqlFileToExecute,"r+");
$sqlFile = fread($f,filesize($sqlFileToExecute));
$sqlArray = explode(';',$sqlFile);
//Process the sql file by statements
foreach ($sqlArray as $stmt) {
if (strlen($stmt)>3){
$result = mysql_query($stmt);
if (!$result){
$sqlErrorCode = mysql_errno();
$sqlErrorText = mysql_error();
$sqlStmt = $stmt;
break;
}
}
}}
echo '<table> ';
if ($sqlErrorCode == 0){
echo "<tr><td>Installation was finished succesfully!</td></tr>";
} else {
echo "<tr><td>An error occured during installation!</td></tr>";
echo "<tr><td>Error code: $sqlErrorCode</td></tr>";
echo "<tr><td>Error text: $sqlErrorText</td></tr>";
echo "<tr><td>Statement:<br/> $sqlStmt</td></tr>";
}
echo '</table>'
?>
Last edited: