0

Hi It seems that both bindParam or bindValue methods will not work.

Please advise. I tried to bind the $dbname to dbtest. It does not seem to work!

bindParam

$dbname = "test1";
$stmt=$dbh->prepare('use :dbtest');
$stmt->bindParam(':dbtest', $dbname, PDO::PARAM_STR);
$firephp->fb($stmt); 
try
{   $stmt->execute();
    $stmt=$dbh->prepare('select database()');
    $stmt->execute();
    $count = $stmt->fetch(PDO::FETCH_ASSOC);
    $firephp->warn("Attempting to use selected database is successful.");
}    

bindValue

$dbname = "test1";
$stmt=$dbh->prepare('use :dbtest');
$stmt->bindValue(':dbtest', $dbname, PDO::PARAM_STR);
$firephp->fb($stmt); 
try
{   $stmt->execute();
    $stmt=$dbh->prepare('select database()');
    $stmt->execute();
    $count = $stmt->fetch(PDO::FETCH_ASSOC);
    $firephp->warn("Attempting to use selected database is successful.");
    $firephp->fb($count);
}    

What could be the problem?

peterm
  • 91,357
  • 15
  • 148
  • 157
user1739825
  • 820
  • 4
  • 10
  • 27

1 Answers1

0

First, native prepared statements won't work for identifiers
Second, there is no point in having dynamically bound databases. They are supposed to be constant.

So, select your database in DSN and then use bindValue to bind values in the query.

Community
  • 1
  • 1
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345