Axel Nordh %!s(int64=5) %!d(string=hai) anos
pai
achega
80c69e7023
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      dbFiles/ReadQuestionsFromFile.php

+ 7 - 2
dbFiles/ReadQuestionsFromFile.php

@@ -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)