public function importModels(Import $entity, $output) { $em = $this->container->get('doctrine')->getManager(); $sql = ' SELECT m.id_modelo, m.id_marca, m.nombre, m.slug, mm.nombre as marca FROM `modelo` AS m ' . ' LEFT JOIN marca AS mm ON m.id_marca = mm.id_marca ' . ' ORDER BY m.id_marca '; // . ' LIMIT '.$entity->getLimitStart().', '.$entity->getLimitEnd(); $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link)); $resultado = $link->query($sql); $arrayBrand = array(); if (mysqli_num_rows($resultado) > 0) { while ($fila = mysqli_fetch_assoc($resultado)) { $brand = $em->getRepository('EcommerceBundle:Brand')->findOneByName(utf8_encode($fila['marca'])); $brandModel = $em->getRepository('EcommerceBundle:BrandModel')->findOneByName(utf8_encode($fila['nombre'])); if (!$brandModel instanceof BrandModel) { if (!in_array(utf8_encode($fila['nombre']), $arrayBrand)) { //Create BrandModel $brandModel = new BrandModel(); $brandModel->setName(utf8_encode($fila['nombre'])); $brandModel->setAvailable(true); if ($brand instanceof Brand) { $brandModel->setBrand($brand); } $em->persist($brandModel); $arrayBrand[] = utf8_encode($fila['nombre']); } } } $em->flush(); } }