|
|
@@ -23,7 +23,7 @@ if (file_exists($argv[1])) {
|
|
|
|
|
|
while (($data = fgetcsv($file, 1000, ",")) !== false) {
|
|
|
$answer = intval($data[0]);
|
|
|
- $question = utf8_encode($data[1]);
|
|
|
+ $question = $data[1];
|
|
|
|
|
|
if ($answer == null || $question == null || $answer == "" || $question == "") {
|
|
|
echo "Failed to get answer and/or question from " . print_r($data,true) . "\r\n";
|
|
|
@@ -35,8 +35,9 @@ if (file_exists($argv[1])) {
|
|
|
if ($result === FALSE) {
|
|
|
echo "Insert new question $question \r\n";
|
|
|
} else {
|
|
|
- $questionId = $conn->query($sql)->fetch_object()->id;
|
|
|
+ $questionId = $result->fetch_object()->id;
|
|
|
}
|
|
|
+$result->free_result();
|
|
|
|
|
|
if($questionId == null) {
|
|
|
$sql = "INSERT INTO questions (answer, question)
|
|
|
@@ -56,7 +57,13 @@ if (file_exists($argv[1])) {
|
|
|
}
|
|
|
|
|
|
$sql = "SELECT id FROM category WHERE name = '$categoryName'";
|
|
|
- $categoryId = $conn->query($sql)->fetch_object()->id;
|
|
|
+ $result = $conn->query($sql);
|
|
|
+ if ($result === FALSE) {
|
|
|
+ echo "Failed to get category, add New with name $categoryName";
|
|
|
+ } else {
|
|
|
+ $categoryId = $result->fetch_object()->id;
|
|
|
+ }
|
|
|
+$result->free_result();
|
|
|
|
|
|
if ($categoryId == null) {
|
|
|
$sql = "INSERT INTO category (name, r,g,b,a) VALUES ($categoryName, 255,255,255,255)";
|
|
|
@@ -73,4 +80,4 @@ if (file_exists($argv[1])) {
|
|
|
fclose($file);
|
|
|
} else {
|
|
|
echo "Run with file as first argument";
|
|
|
-}
|
|
|
+}
|