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 9188773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:05:35+00:00 2026-06-17T20:05:35+00:00

I cannot for the life of me get binding to work with PDO queries,

  • 0

I cannot for the life of me get binding to work with PDO queries, they always return false.

On this example, it checks that the value of a field is between 2 other values.

This works:

$query = $db->query("SELECT * FROM table WHERE field1 > '$start' AND field1 < '$finish'");

This doesn’t:

$query = $db->query("SELECT * FROM table WHERE field1 > :start AND field1 < :finish");
$query->bindParam(":start", $start);
$query->bindParam(":finish", $finish);

UPDATE: The above query now works thanks to the help. The following still doesn’t.

I have been trawling through various PDO posts on here but I have not found a solution, and I don’t know what else to try.

UPDATE2: Okay, it seems it is not finding $db and therefore not connecting and returning false. The $db connection line is in a connect.php file that is required on all main pages. The content on those pages is called by a function that then includes the relevant file/page. Because PDO does not work by itself in functions, is it losing the $db through the function to include the file containing the query? I may not have explained myself clearly enough.

Basically, example function in functions.php:

function getRegistration() {
    include("registration.php");
}

main.php

require_once("connect.php");
require_once("functions.php");

getRegistration();

registration.php contains:

$sql = $db->prepare("INSERT INTO tempus_members(username, email, password, activation_code, registration_date, registered_ip, name) VALUES(:username, :email, :password, :activation_code, :registration_date, :registered_ip, :name)");
$sql->bindParam(":username", $username);
$sql->bindParam(":email", $email);
$sql->bindParam(":password", $hash);
$sql->bindParam(":activation_code", $activation_code);
$sql->bindParam(":registration_date", $registration_date);
$sql->bindParam(":registered_ip", $registered_ip);
$sql->bindParam(":name", $name);
$sql->execute();

Is it losing the $db variable through the function to include the page? If so, how do I carry $db through all functions?

  • 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-17T20:05:36+00:00Added an answer on June 17, 2026 at 8:05 pm

    Try:

    $stmt = $db->prepare("SELECT * FROM table WHERE field1 > :start AND field1 < :finish");
    $stmt->bindParam(":start", $start);
    $stmt->bindParam(":finish", $finish);
    $stmt->execute();
    

    You were using PDO::query instead of PDO::prepare.

    As for the other query, what errors are you getting back? Try the following code and see if any errors are spit out onto the page:

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    try{
        $sql = $db->prepare("INSERT INTO tempus_members(username, email, password, activation_code, registration_date, registered_ip, name) VALUES(:username, :email, :password, :activation_code, :registration_date, :registered_ip, :name)");
    
        $sql->bindParam(":username", $username);
        $sql->bindParam(":email", $email);
        $sql->bindParam(":password", $hash);
        $sql->bindParam(":activation_code", $activation_code);
        $sql->bindParam(":registration_date", $registration_date);
        $sql->bindParam(":registered_ip", $registered_ip);
        $sql->bindParam(":name", $name);
    
        $sql->execute();
    
    }
    catch(PDOException $e){
        echo $e->getMessage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot for the life of me get this. Example of fails, the last
I cannot get Bindable LINQ to work with VB.NET for the life of me.
I cannot work this out to save my life! So, I have a Codeigniter
I cannot for the life of me get lists:keyfind to work as I expect
My maths is shocking & I cannot, for the life of me get this
By some curse i cannot for the life of me get this simple css
I cannot for the life of me get bootstrap (or jquery-collapse for that sake)
Why does this code only draw a circle once? I cannot for the life
Trying to get this to work, and not sure what I'm missing. The idea
Cannot for the life of me get Heroku to build a skeleton database for

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.