Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeing default value inserted into columns when calling query() function with question mark placeholders #83

Open
ducnguyenvn opened this issue Jun 8, 2016 · 4 comments

Comments

@ducnguyenvn
Copy link

Hi,

The below is my code:

$sql = 'insert into my_table (name, amount) values (?, ?)'
$params = array( 0 => "Messi", 1 => 100)
$db->query($sql, $params);

Then I check database and see that a new row inserted but with default values instead of my values.

Could you please correct me?

Thanks.

@joejordanbrown
Copy link

I've not used this in a while but i think this is how it should be.

$sql = 'INSERT INTO my_table (name, amount) VALUES (?, ?)';
$params = array("Messi", 100);
$db->query($sql, $params);

@ducnguyenvn
Copy link
Author

Thanks but it's same code. Still error.

@joejordanbrown
Copy link

Actually reviewing the source code it doesn't look to accept that method. Is there any reason you can't use the other method?

What about just plain PHP PDO prepare?

$prep = $dbh->prepare('INSERT INTO my_table (name, amount) VALUES (?, ?)');
$prep->execute(array('Messi', 100));

@ducnguyenvn
Copy link
Author

ducnguyenvn commented Jun 9, 2016

Yes, Seem this lib doest not support that. This is the bind function in DB.class.php in this lib:

public function bind($para, $value)
    {
          $this->parameters[sizeof($this->parameters)] = [":" . $para , $value];
    }

And I updated it to followings so that it works in my case:

public function bind($para, $value)
    {
        if (is_int($para)) {
          $this->parameters[sizeof($this->parameters)] = [++$para , $value];
        } else {
          $this->parameters[sizeof($this->parameters)] = [":" . $para , $value];
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants