M
M
Matvey Mamonov2015-07-08 16:17:44
PHP
Matvey Mamonov, 2015-07-08 16:17:44

Whence the error at SQL request undertook?

try {
        
        $dsn = "mysql:host=localhost;dbname=main";
        $opt = array(
        
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
          PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
          
        );
        
        $DBH = new PDO($dsn, "root", "pass", $opt);
        
          $STH = $DBH->prepare("INSERT INTO users (username, date) VALUES(smellyshovel,5)");

        
          $STH->execute();
        
        $answer = $STH->fetch();
        print $answer;
        
      } catch(PDOException $e) {  
        print($e->getMessage());
      }
      
      $DBH = null;

I ask you not to find fault with the quality, as it was copied from a very old project.
So for some reason it throws an error when executing
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'smellyshovel' in 'field list'

smellyshovel is a database user with root permissions.
I also tried to send a request from root (in this case, there was not a single word about smellyshovel in the script), but it still makes the same error.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Matvey Mamonov, 2015-07-08
@eucalipt

Very stupid:
What fetch () can be with an INSERT query? XD

S
Swartalf, 2015-07-08
@Swartalf

Column not found : 1054 Unknown column 'smellyshovel' in 'field list'
check the database for fields or the correct field name in the query.

S
Stanislav Makarov, 2015-07-08
@Nipheris

where does $what come from? there is a feeling that it was there that "smellyshovel" turned out to be, it is not clear why the truth is, because this error is explicit when trying to execute select.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question