Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:11:21+00:00 2026-06-07T08:11:21+00:00

Just recently I’ve switched to using PDO in PHP/MySQL and transformed some dozens of

  • 0

Just recently I’ve switched to using PDO in PHP/MySQL and transformed some dozens of queries. Most of them worked, however this very easy one throws an exception at $sql->execute()

$sql=$pdo->prepare("SELECT id FROM user WHERE username = :username LIMIT 1");
$sql->execute(array(':username',$username));

PDOStatement::execute() pdostatement.execute SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in …

After research, I found this link: https://bugs.php.net/bug.php?id=60515

… and therefore tried to change the query to

$sql=$pdo->prepare("SELECT `id` FROM `user` WHERE `username` = :username LIMIT 1");
$sql->execute(array(':username',$username));

But still with the same result. Does anybody see what is obviously wrong or why does this query not work when all others did?

Thank you very much in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:11:22+00:00Added an answer on June 7, 2026 at 8:11 am

    The ':username',$username works only in bindParam() method:

    $sql->bindParam(':username', $username, PDO::PARAM_STR);
    

    Take a look here: http://www.php.net/manual/en/pdostatement.bindparam.php

    For execute you need to pass a correct array of input-only values:

    $sql->execute(array(':username' => $username));
    

    Placeholder:

    You can also use this:

    $sql->execute(array($username));
    

    But for this you need to change your query to this:

    $sql=$pdo->prepare("SELECT `id` FROM `user` WHERE `username` = ? LIMIT 1");    
    

    The ? works as palceholder and take the variables from the array. When you use more placeholder in your SQL statement the function takes all the variables out of the array in it’s order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just recently switched to using the NullSoft Installer for my .NET application. By
I just recently started diving into Real World Haskell and the book provides some
I just recently started using this library (the one from CodePlex), but I ran
I just recently started using Jinja2 for HTML templating on Google App Engine and
I just recently upgraded to MySQL 5.1.6 in order to take advantage of the
I just recently started using Mono for Android and I am trying to consume
I just recently started working with Qt 4.7.4 64-bit in order to make some
I just recently started using Hudson as a CI server for a project of
I just recently started learning and using the ADO.NET Entity Framework and ran into
I just recently made the move to Objective-C. I am doing some exercises from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.