K
K
Kagtaviy2016-06-10 17:22:58
JavaScript
Kagtaviy, 2016-06-10 17:22:58

How to solve query problem in mysql golang?

Hello, I've been struggling with this problem for a day now.
Connecting to Mysql database

db, err := sql.Open("mysql", "user:[email protected]/dbname")
  defer db.Close()
  if err != nil {
    panic(err)
  }

Then I want to check for matches in the database, I execute the code:
key := 1545
  var user_key string
  err = db.QueryRow("SELECT * FROM users WHERE user_key=?", key).Scan(&user_key)
  switch {
  case err == sql.ErrNoRows:
    log.Printf("No user with that key.")
  case err != nil:
    log.Fatal(err)
  default:
    fmt.Println("User key, ", user_key)
  }

table in mysql:
CREATE TABLE `users` (
  `user_id` INT(10) NOT NULL AUTO_INCREMENT,
  `user_key` INT(11) NULL DEFAULT '0',
  `user_login` VARCHAR(35) NULL DEFAULT '0',
  PRIMARY KEY (`user_id`)
)

Here is what is returned in the log:
2016/06/10 10:17:54 sql: expected 3 destination arguments in Scan, not 1

Tell me how to solve the problem, I went to Google more than once!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Ukolov, 2015-10-16
@lynnikvadim

Because the syntax is wrong, as you were told.
If you remove all your code, you get complete crap:

$(".svg").each(
    function(){
        (
            function () { /* Тут ваш код, который, кажется, должен работать нормально */ };
            window.deSVG = desvg;
    }
    )();
    deSVG(".svg", true);
    }
);

A
AlexeyVD, 2016-06-10
@Kagtaviy

Replace
with
SELECT user_key FROM ...

A
Alexander Semchenko, 2016-06-10
@0xcffaedfe

Your problem is easily solved by reading the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question