public function importDataAction(Request $request) { $em = $this->getDoctrine()->getEntityManager(); $link = mysql_connect('localhost', 'root', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } else { mysql_select_db('sample_drp'); $queryData = "select * from Provincial_Lease"; $resultData = mysql_query($queryData, $link); $arrData = array(); while ($rowData = mysql_fetch_Array($resultData, MYSQL_ASSOC)) { $arrData[] = $rowData; //echo"<pre>";print_r($arrData);die; $propertyData = new Book(); $propertyData->SetSerialNumber($rowData['Serial_registration']); //$propertyData->SetReferenceNumber($arrCells[0]); $propertyData->SetExecutionDate($rowData['Date_of_execution']); $propertyData->SetReceiptDate($rowData['Date_of_receipt']); $propertyData->SetLandSituation($rowData['Situation_of_land']); $propertyData->SetOrNumber($rowData['O_R_Number']); $propertyData->SetStampDuty($rowData['Stamp_duty']); $propertyData->SetLomp($rowData['LOMP']); $propertyData->SetRegistrationType('PL'); $em->persist($propertyData); $em->flush(); $id = $propertyData->getId(); $companyDataGR = new Company(); $companyDataGR->SetFirstName($rowData['Lessor_fname']); $companyDataGR->SetLastName($rowData['Lessor_lname']); $companyDataGR->SetNin($rowData['Lessor_NIN']); $companyDataGR->SetDob($rowData['Lessor_DOB']); $companyDataGR->SetTelephone1($rowData['Lessor_tel1']); $companyDataGR->SetEmail($rowData['Lessor_email']); $companyDataGR->SetAddress($rowData['Lessor_Address']); $companyDataGR->SetTelephone2($rowData['Lessor_tel2']); $companyDataGR->SetBookId($id); $companyDataGR->SetType('LR'); $em->persist($companyDataGR); $em->flush(); $companyDataGE = new Company(); $companyDataGE->SetFirstName($rowData['Lessee_fname']); $companyDataGE->SetLastName($rowData['lessee_lname']); $companyDataGE->SetNin($rowData['Lessee_NIN']); $companyDataGE->SetDob($rowData['Lessee_DOB']); $companyDataGE->SetTelephone1($rowData['Lessee_tel1']); $companyDataGE->SetEmail($rowData['lessee_email']); $companyDataGE->SetTelephone2($rowData['Lessee_tel2']); $companyDataGE->SetAddress($rowData['Lessee_address']); $companyDataGE->SetBookId($id); $companyDataGE->SetType('LE'); $em->persist($companyDataGE); $em->flush(); $companyDataPR = new Company(); $companyDataPR->SetFirstName($rowData['PR_fname']); $companyDataPR->SetLastName($rowData['PR_lname']); $companyDataPR->SetNin($rowData['PR_NIN']); $companyDataPR->SetDob($rowData['PR_DOB']); $companyDataPR->SetTelephone1($rowData['PR_tel1']); $companyDataPR->SetEmail($rowData['PR_email']); $companyDataPR->SetTelephone2($rowData['PR_tel2']); $companyDataPR->SetAddress($rowData['PR_address']); $companyDataPR->SetBookId($id); $companyDataPR->SetType('PR'); $em->persist($companyDataPR); $em->flush(); $companyDataRP = new Company(); $companyDataRP->SetFirstName($rowData['Recipient_fname']); $companyDataRP->SetLastName($rowData['recipient_lname']); $companyDataRP->SetNin($rowData['recipient_NIN']); $companyDataRP->SetDob($rowData['recipient_DOB']); $companyDataRP->SetTelephone1($rowData['recipient_tel1']); $companyDataRP->SetEmail($rowData['recipient_email']); $companyDataRP->SetTelephone2($rowData['recipient_tel2']); $companyDataRP->SetAddress($rowData['recipient_address']); $companyDataRP->SetBookId($id); $companyDataRP->SetType('RP'); $em->persist($companyDataRP); $em->flush(); $status = new RegistrationStatus(); $status->SetStatus(0); $status->SetPropertyType('lease'); $status->SetBookId($id); $em->persist($status); $em->flush(); } } mysql_close($link); if ($request->getMethod() == 'POST') { if (is_uploaded_file($_FILES['file']['tmp_name'])) { //readfile($_FILES['file']['tmp_name']); } $i = 0; $handle = fopen($_FILES['file']['tmp_name'], "r"); while (($data = fgetcsv($handle, 10000000, ",")) !== FALSE) { if ($i > 2) { $arrCells = explode(',', $data[0]); echo "<pre>"; print_r($arrCells); die; } $i++; } } return $this->render('DRPAdminBundle:Pages:importData.html.twig'); }