Manage mappage data Symfony











up vote
1
down vote

favorite












I'm working on a project on data mapping. Several checks are realized:




  • well imported file


  • table choice


  • columns choice of the table


  • typage of data



I'm for at the part of the typage of data for the moment. I'm stocking these various data in an array. The problem is that I don't know exactly how to detect number of columns choosed in order to store data in database
I'im using Symfony. I get this error when trying to store data :




SQLSTATE[21S01]: Insert value list does not match column list: 1136
Column count doesn't match value count at row 1




/**
* @Route("/result/", name="result")
* @param Request $request
*/
function resultAction(Request $request)
{
$session = $request->getSession();

$choiceMapping = $session->get('choiceMapping');
$tableChoice = $session->get('tableChoice');
$selectChoiceFields = implode(",", $session->get('selectChoiceFields'));
$choiceData = $session->get('choiceData');
var_dump($choiceData);

$config = new Configuration();

$connectionParams = array(
'dbname' => 'mapping',
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',
);

$conn = DriverManager::getConnection($connectionParams, $config);

$sm = $conn->getSchemaManager();

$tableDetails = $sm->listTableColumns($session->get('tableChoice'));

if(sizeof($selectChoiceFields[0]) === 0)
{
$addFlash = $this->addFlash('danger', 'Please choose at least one field !');
return $this->redirectToRoute('mapping');
}

$host = '127.0.0.1';
$db = 'JAgestionDonnees';
$user = 'root';
$pass = '';
$charset = 'utf8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];

try
{
$cnx = new PDO($dsn, $user, $pass, $opt);
}
catch(PDOException $e)
{
die('Connection failed :'. $e->getMessage());
}

if($choiceMapping === "completion")
{
//$values = str_replace(",", ' UNION SELECT ', $choiceData);
$content = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES ('.$choiceData.')');
$addFlash = $this->addFlash('success', "record completed !");
}
}
else
{
$content = $cnx->prepare('Truncate '.$session->get('tableChoice'));
$content->execute();

$sql = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES (:choiceData)');
$sql->bindValue(':choiceData', $choiceData[0]);
$sql->execute();

$addFlash = $this->addFlash('success', "record completed !");
}

return $this->render('result.html.twig');
}









share|improve this question






















  • Why you don't load information to an object and let the Entity Manager to do his job?
    – GasKa
    Nov 19 at 10:57















up vote
1
down vote

favorite












I'm working on a project on data mapping. Several checks are realized:




  • well imported file


  • table choice


  • columns choice of the table


  • typage of data



I'm for at the part of the typage of data for the moment. I'm stocking these various data in an array. The problem is that I don't know exactly how to detect number of columns choosed in order to store data in database
I'im using Symfony. I get this error when trying to store data :




SQLSTATE[21S01]: Insert value list does not match column list: 1136
Column count doesn't match value count at row 1




/**
* @Route("/result/", name="result")
* @param Request $request
*/
function resultAction(Request $request)
{
$session = $request->getSession();

$choiceMapping = $session->get('choiceMapping');
$tableChoice = $session->get('tableChoice');
$selectChoiceFields = implode(",", $session->get('selectChoiceFields'));
$choiceData = $session->get('choiceData');
var_dump($choiceData);

$config = new Configuration();

$connectionParams = array(
'dbname' => 'mapping',
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',
);

$conn = DriverManager::getConnection($connectionParams, $config);

$sm = $conn->getSchemaManager();

$tableDetails = $sm->listTableColumns($session->get('tableChoice'));

if(sizeof($selectChoiceFields[0]) === 0)
{
$addFlash = $this->addFlash('danger', 'Please choose at least one field !');
return $this->redirectToRoute('mapping');
}

$host = '127.0.0.1';
$db = 'JAgestionDonnees';
$user = 'root';
$pass = '';
$charset = 'utf8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];

try
{
$cnx = new PDO($dsn, $user, $pass, $opt);
}
catch(PDOException $e)
{
die('Connection failed :'. $e->getMessage());
}

if($choiceMapping === "completion")
{
//$values = str_replace(",", ' UNION SELECT ', $choiceData);
$content = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES ('.$choiceData.')');
$addFlash = $this->addFlash('success', "record completed !");
}
}
else
{
$content = $cnx->prepare('Truncate '.$session->get('tableChoice'));
$content->execute();

$sql = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES (:choiceData)');
$sql->bindValue(':choiceData', $choiceData[0]);
$sql->execute();

$addFlash = $this->addFlash('success', "record completed !");
}

return $this->render('result.html.twig');
}









share|improve this question






















  • Why you don't load information to an object and let the Entity Manager to do his job?
    – GasKa
    Nov 19 at 10:57













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm working on a project on data mapping. Several checks are realized:




  • well imported file


  • table choice


  • columns choice of the table


  • typage of data



I'm for at the part of the typage of data for the moment. I'm stocking these various data in an array. The problem is that I don't know exactly how to detect number of columns choosed in order to store data in database
I'im using Symfony. I get this error when trying to store data :




SQLSTATE[21S01]: Insert value list does not match column list: 1136
Column count doesn't match value count at row 1




/**
* @Route("/result/", name="result")
* @param Request $request
*/
function resultAction(Request $request)
{
$session = $request->getSession();

$choiceMapping = $session->get('choiceMapping');
$tableChoice = $session->get('tableChoice');
$selectChoiceFields = implode(",", $session->get('selectChoiceFields'));
$choiceData = $session->get('choiceData');
var_dump($choiceData);

$config = new Configuration();

$connectionParams = array(
'dbname' => 'mapping',
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',
);

$conn = DriverManager::getConnection($connectionParams, $config);

$sm = $conn->getSchemaManager();

$tableDetails = $sm->listTableColumns($session->get('tableChoice'));

if(sizeof($selectChoiceFields[0]) === 0)
{
$addFlash = $this->addFlash('danger', 'Please choose at least one field !');
return $this->redirectToRoute('mapping');
}

$host = '127.0.0.1';
$db = 'JAgestionDonnees';
$user = 'root';
$pass = '';
$charset = 'utf8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];

try
{
$cnx = new PDO($dsn, $user, $pass, $opt);
}
catch(PDOException $e)
{
die('Connection failed :'. $e->getMessage());
}

if($choiceMapping === "completion")
{
//$values = str_replace(",", ' UNION SELECT ', $choiceData);
$content = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES ('.$choiceData.')');
$addFlash = $this->addFlash('success', "record completed !");
}
}
else
{
$content = $cnx->prepare('Truncate '.$session->get('tableChoice'));
$content->execute();

$sql = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES (:choiceData)');
$sql->bindValue(':choiceData', $choiceData[0]);
$sql->execute();

$addFlash = $this->addFlash('success', "record completed !");
}

return $this->render('result.html.twig');
}









share|improve this question













I'm working on a project on data mapping. Several checks are realized:




  • well imported file


  • table choice


  • columns choice of the table


  • typage of data



I'm for at the part of the typage of data for the moment. I'm stocking these various data in an array. The problem is that I don't know exactly how to detect number of columns choosed in order to store data in database
I'im using Symfony. I get this error when trying to store data :




SQLSTATE[21S01]: Insert value list does not match column list: 1136
Column count doesn't match value count at row 1




/**
* @Route("/result/", name="result")
* @param Request $request
*/
function resultAction(Request $request)
{
$session = $request->getSession();

$choiceMapping = $session->get('choiceMapping');
$tableChoice = $session->get('tableChoice');
$selectChoiceFields = implode(",", $session->get('selectChoiceFields'));
$choiceData = $session->get('choiceData');
var_dump($choiceData);

$config = new Configuration();

$connectionParams = array(
'dbname' => 'mapping',
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',
);

$conn = DriverManager::getConnection($connectionParams, $config);

$sm = $conn->getSchemaManager();

$tableDetails = $sm->listTableColumns($session->get('tableChoice'));

if(sizeof($selectChoiceFields[0]) === 0)
{
$addFlash = $this->addFlash('danger', 'Please choose at least one field !');
return $this->redirectToRoute('mapping');
}

$host = '127.0.0.1';
$db = 'JAgestionDonnees';
$user = 'root';
$pass = '';
$charset = 'utf8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];

try
{
$cnx = new PDO($dsn, $user, $pass, $opt);
}
catch(PDOException $e)
{
die('Connection failed :'. $e->getMessage());
}

if($choiceMapping === "completion")
{
//$values = str_replace(",", ' UNION SELECT ', $choiceData);
$content = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES ('.$choiceData.')');
$addFlash = $this->addFlash('success', "record completed !");
}
}
else
{
$content = $cnx->prepare('Truncate '.$session->get('tableChoice'));
$content->execute();

$sql = $cnx->prepare('INSERT INTO '.$session->get('tableChoice').' ('.$selectChoiceFields.') VALUES (:choiceData)');
$sql->bindValue(':choiceData', $choiceData[0]);
$sql->execute();

$addFlash = $this->addFlash('success', "record completed !");
}

return $this->render('result.html.twig');
}






php jquery symfony






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 8:25









Maestro

1209




1209












  • Why you don't load information to an object and let the Entity Manager to do his job?
    – GasKa
    Nov 19 at 10:57


















  • Why you don't load information to an object and let the Entity Manager to do his job?
    – GasKa
    Nov 19 at 10:57
















Why you don't load information to an object and let the Entity Manager to do his job?
– GasKa
Nov 19 at 10:57




Why you don't load information to an object and let the Entity Manager to do his job?
– GasKa
Nov 19 at 10:57

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370792%2fmanage-mappage-data-symfony%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370792%2fmanage-mappage-data-symfony%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin