0

trying to parametrize my queries, heres a supposedly simple one

        $query = $this->handle->prepare('USE :db_name');
        $query->bindParam(':db_name', $db_name, PDO::PARAM_STR);
        $query->execute();

however, it throws an invalid syntax error. I checked the query log, it comes out as

USE 'test'

which doesn't work, however, if I manually write

USE test

then that does work. This leaves me with 2 questions

  1. Shouldn't the one with single quotes work? AFAIK, quotes just mark the beginning and ending of a string in SQL, why is it breaking it?

  2. How can I get the prepared query to not automatically put quotation marks around the parameters?

user81993
  • 6,167
  • 6
  • 32
  • 64

0 Answers0