Questions tagged [bindvalue]

In PHP, binds a value to a corresponding named or question mark parameter in the SQL statement that was used to prepare the statement.

Binds a value to a corresponding named or question mark parameter in the SQL statement that was used to prepare the statement.

public bool PDOStatement::bindValue ( mixed $parameter , mixed $value [, int $data_type = PDO::PARAM_STR ] )

Example #1 Execute a prepared statement with named parameter

<?php
/* Execute a prepared statement by binding values */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour');
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
$sth->bindValue(':colour', $colour, PDO::PARAM_STR);
$sth->execute();
?>

Reference

PHP Documentation

87 questions
2
votes
1 answer

How prepare statement with bindvalue and %?

Yes I have a issue when i try to use bindvalues on the variables that looked like this before: users.firstname LIKE '$firstname%' Now it looks like this: users.firstname LIKE ':firstname%' But it doesn't work, also tried this: users.firstname LIKE…
Karem
  • 17,615
  • 72
  • 178
  • 278
2
votes
1 answer

Yii2 - Is it possible to not quote parameters passed in by bindValues()?

I am trying to query a column with createCommand doing something like this: Yii::$app->db->createCommand('Select column1 from table where column2 in :array) ->bindValues(['array'=>['(1,2,3,4,5)', …
user3504410
  • 173
  • 1
  • 13
2
votes
1 answer

How do I bind a bigint value in PHP using PDO?

I have a column in a PostgreSQL database which is a bigint. So far I am not able to find a way formulate a PDO insert in PHP. PHP Predefined Constants only lists PDO::PARAM_INT. When I use this in my statement, I get the following error. Note, I get…
quickblueblur
  • 168
  • 1
  • 12
2
votes
0 answers

Print SQLite query in PHP

I'm using PHP with SQLite3 to manage some website sessions and I'm having troubles with a query that doesn't return results. The thing is I want to print the query before the execute command but I can't find the way to do it. More specifically, I'm…
dubafek
  • 1,073
  • 9
  • 21
2
votes
1 answer

Why bindValue or BindParam doesn't modify the prepared statement?

Using latest php in order to create a function that adds a row to table user. class targil_db { private $_pdo; public function __construct() { // username: root password: database: targil $this->_pdo = new PDO( …
ufk
  • 30,912
  • 70
  • 235
  • 386
1
vote
2 answers

QT SQL bindValue issue

I got problem for using the bindValue in QT with SQLite3. The below statement don't work.The exec is success but result incorrect. query5.prepare("select DISTINCT :col_readback FROM Equipment"); query5.bindValue(":col_readback",…
1
vote
2 answers

How to bind selected option with the attribut in Svelte

I have a svelte component where i want to connect a selected input with a declared attribute. My problem is that the binding of the selected value of status to the attribute'status' declared in 'flightschedules' doesnt work. The options are from the…
1
vote
1 answer

PHP bindValue for SQL statement doesnt work inside function

I often create functions when code is duplicated several times. In this instance, I'm building SQL queries and binding the parameters afterwards. The query works if I dont try to bind inside a function, but the code is so much cleaner looking with…
mthoodpdx
  • 21
  • 3
1
vote
1 answer

bindValue does not escape

I read a comment at php.net: Although bindValue() escapes quotes it does not escape "%" and "_", so be careful when using LIKE. A malicious parameter full of %%% can dump your entire database if you don't escape the parameter yourself. PDO does not…
Proyb2
  • 995
  • 6
  • 13
  • 35
1
vote
1 answer

PDO BindValue doesn't work but works with direct paste

So I have some code //passed as function param $clause[2] = "'2016-09-09' AND '2016-09-09'" $sql = "SELECT {$columns} FROM `{$table}` WHERE `{$clause[0]}` {$clause[1]} :clause"; $stm = $this->db->prepare($sql); $stm->bindValue("clause",…
MisterQuacker
  • 35
  • 1
  • 6
1
vote
3 answers

What does ":" mean when using bindValue() in PHP PDO?

What does : mean before id in the example below? Is it necessary? $sth->bindValue(':id', $id, PDO::PARAM_INT); Can I say :id is a variable? If PDO::PARAM_INT is not necessary, why would I need to use it?
Eduardo
  • 99
  • 2
  • 11
1
vote
2 answers

PDO->bindParam, PDO->bindValue and PDO->closeCursor

So far I have been using PDO->bindParam however while reading the manual I found PDO->bindValue from what I can tell PDO->bindValue passes by value where as PDO->bindParam passes by reference, is this the only difference? $modThread =…
Johnny
  • 1,963
  • 4
  • 21
  • 24
1
vote
0 answers

PHP: PDO dynamic bindValue

I'm probably missing something simple here. I'm trying to dynamically populate bindValue statements. From what I can tell they work up until they reach a set of code that pulls in key and value pairs from a dynamically generated set of facets. The…
CODR
  • 19
  • 2
1
vote
1 answer

Yii2 bindValue in LIKE condition

How can I do a wildcard search using bindValue(:name, $name) in LIKE condition given this query: $post = Yii::$app->db->createCommand('SELECT * FROM fruits WHERE name LIKE %:name%') ->bindValue(':name', 'apple') ->queryOne();
C. Norris
  • 615
  • 1
  • 7
  • 17
1
vote
1 answer

PDO/PHP - bindValue does not seem to be working

According to everything I've found and seen, this seems correct. When I print $query the outcome is the following: "INSERT INTO customers (FirstName, MiddleInit, LastName, Address, City, State, Zip, Email, Gender) VALUES (?,?,?,?,?,?,?,?,?)" The…
mallorz
  • 55
  • 1
  • 8