3

I am new to PHP.

My client shared the 5GB XML product information data.

I need to import in this data in DB.

I have used the below code and run in the browser.

<?php 
ini_set('max_execution_time', 0);
ini_set('memory_limit', '6144M');

$mysql_hostname = "localhost";
$mysql_user     = "XXXX";
$mysql_password = "XXXX";
$mysql_database = "XXXX";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");

$languages = simplexml_load_file("sample.xml");
$total_row =  count($languages->entry);
$data = $languages->entry;

foreach($data as $key => $value) {
    $title = $value->title; 
    $sql   = "INSERT INTO `YYYY` VALUES ( NULL, '$title')";
    $run = mysql_query($sql);  
}
echo "Completed ...... !";
?>

I am getting below error message.

error message

Apache Error log:

[Mon Feb 15 12:24:40.140480 2016] [mpm_winnt:notice] [pid 4752:tid 260] AH00428: Parent: child process 5244 exited with status 3221225477 -- Restarting.
[Mon Feb 15 12:24:40.510501 2016] [ssl:warn] [pid 4752:tid 260] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Mon Feb 15 12:24:40.567504 2016] [mpm_winnt:notice] [pid 4752:tid 260] AH00455: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.30 configured -- resuming normal operations
[Mon Feb 15 12:24:40.567504 2016] [mpm_winnt:notice] [pid 4752:tid 260] AH00456: Apache Lounge VC11 Server built: Oct 13 2015 10:54:13
[Mon Feb 15 12:24:40.567504 2016] [core:notice] [pid 4752:tid 260] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Mon Feb 15 12:24:40.569505 2016] [mpm_winnt:notice] [pid 4752:tid 260] AH00418: Parent: Created child process 5032
[Mon Feb 15 12:24:40.946526 2016] [ssl:warn] [pid 5032:tid 272] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Mon Feb 15 12:24:41.091534 2016] [ssl:warn] [pid 5032:tid 272] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Mon Feb 15 12:24:41.121536 2016] [mpm_winnt:notice] [pid 5032:tid 272] AH00354: Child: Starting 150 worker threads. 

How to achive this ??

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
Vishal
  • 61
  • 3

1 Answers1

0

you can improve performance and pass all queries to mysql once:

function str_lreplace($search, $replace, $subject)
{
    $pos = strrpos($subject, $search);

    if($pos !== false)
    {
        $subject = substr_replace($subject, $replace, $pos, strlen($search));
    }

    return $subject;
}

$sql   = "INSERT INTO `YYYY` VALUES ";
foreach($data as $key => $value) {
    $title = $value->title; 
    $sql   =$sql. "( NULL, '$title'),";
    //$run = mysql_query($sql);  
}
//replace last occurrence of a  '),'  with  ');'  in php
$sql = str_lreplace('),',');', $sql);
$run = mysql_query($sql);  
echo "Completed ...... !";
Gouda Elalfy
  • 6,888
  • 1
  • 26
  • 38