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');
}
php jquery symfony
add a comment |
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');
}
php jquery symfony
Why you don't load information to an object and let the Entity Manager to do his job?
– GasKa
Nov 19 at 10:57
add a comment |
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');
}
php jquery symfony
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
php jquery symfony
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Why you don't load information to an object and let the Entity Manager to do his job?
– GasKa
Nov 19 at 10:57