|
|
@@ -23,7 +23,7 @@ if (file_exists($argv[1])) {
|
|
|
|
|
|
while (($data = fgetcsv($file, 1000, ",")) !== false) {
|
|
|
$answer = intval($data[0]);
|
|
|
- $question = $data[1];
|
|
|
+ $question = utf8_encode($data[1]);
|
|
|
|
|
|
if ($answer == null || $question == null || $answer == "" || $question == "") {
|
|
|
echo "Failed to get answer and/or question from " . print_r($data,true) . "\r\n";
|
|
|
@@ -31,7 +31,12 @@ if (file_exists($argv[1])) {
|
|
|
}
|
|
|
|
|
|
$sql = "SELECT id FROM questions WHERE question = '$question'";
|
|
|
- $questionId = $conn->query($sql)->fetch_object()->id;
|
|
|
+ $result = $conn->query($sql);
|
|
|
+ if ($result === FALSE) {
|
|
|
+ echo "Insert new question $question \r\n";
|
|
|
+ } else {
|
|
|
+ $questionId = $conn->query($sql)->fetch_object()->id;
|
|
|
+ }
|
|
|
|
|
|
if($questionId == null) {
|
|
|
$sql = "INSERT INTO questions (answer, question)
|