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
1
vote
1 answer

bindValue / bindParam vs array performance

I have always passed an array of my values into execute as it seemed easier to read imo. I was recently working on a script and noticed it was using bindParam and later came to find out how this passes the variable reference (I never knew). With…
user756659
  • 3,372
  • 13
  • 55
  • 110
1
vote
1 answer

Yii createCommand Update with bindValue

I'm using createCommand in Yii Framework and I want to know about use bindValue for the params, Ex: Yii::app()->db->createCommand() ->update('table', array( 'field'=>'$valuefield', …
1
vote
2 answers

PDO SQLSRV Using bindValue for SELECT TOP

I'm trying to use PDO SQLSRV to select data from a table with a limit (TOP). However, when I do this. $limit = 20; $sql = "SELECT TOP :rowsLimit * FROM TABLE ORDER BY id DESC"; $query = $this->db->prepare($sql); $parameters = array(':rowsLimit' =>…
Wokki
  • 157
  • 2
  • 18
1
vote
1 answer

prepared statement help, 63/63 parameters failing with number of parameters mismatch

i'm having troubles with my prepared statement (mysqli), i'm doing my connection and everything's right until i try to bind parameters, here's the problem, i'ml trying to bind 63 values, and I did check many times i have the right amout of values…
Bxtr
  • 316
  • 1
  • 13
1
vote
0 answers

how can run a query in a insert statement in pdo when i bind my value

i want run a query in a insert statement in pdo when i bind my value with prepare and bindValue functions. i want run a code like this in pdo: INSERT INTO test_table1 (`item1`, `item2`, `item3`) VALUES ( 'value of item1', 'value of…
Morteza
  • 41
  • 4
1
vote
1 answer

Call to a member function bindValue() on a non-object

So I'm trying to create a prepared insert statement to a database for a web app. For the registration system, I'm feeding in values using post, then redirecting to a webpage to do the processing. However, I keep getting the error 'Call to a member…
sjwarner
  • 452
  • 1
  • 7
  • 20
1
vote
3 answers

PHP PDO bindValue() don't work

prepare("SELECT id, name FROM testdb ORDER BY time DESC LIMIT :index, 10"); $stmt->bindValue(":index", $_GET['index'], PDO::PARAM_INT); …
TheMagician
  • 1,846
  • 7
  • 20
  • 26
1
vote
3 answers

PHP PDO bindValue() fails

I'm new to PHP's PDO and got a little problem with a function of my database class: function set($query, $args = array()) { try { $query = $this->rs->prepare($query); $x = 1; foreach($args as $arg) { $query -> bindValue($x,…
1
vote
0 answers

Why bindValue breaks my query?

In below code, I'm trying to bind tags (which is taken from user) to my sql query. I'll put them to query like this format: "tag1","tag2","tag3" $tagsinput = trim($_GET["q"]); $exploded_q = explode(",", trim($_GET["q"])); //seperate with comma,…
alayli
  • 325
  • 1
  • 6
  • 18
1
vote
1 answer

What is the difference between bindValue and having execute(array())?

I've been urging to know what is the difference between using bindValue and execute(array()) thing-y. Well let's say I have this example of code $query = $db->prepare("SELECT embedded_page.uid FROM embedded_page WHERE fbp_id =…
Wesley Brian Lachenal
  • 4,381
  • 9
  • 48
  • 81
1
vote
2 answers

PDO bindValue() is not binding

The idea of the following script is to add or remove a date to / from a datebase based on the user clicking on a date in the jQuery UI datepicker calendar which I have set up to pick up the date clicked. I am sending a jQuery.post() to a php page…
Duck in Custard
  • 1,043
  • 2
  • 10
  • 17
1
vote
1 answer

How bindValue for table name?

Is it possible to do a bindvalue for the table name? mine doesn't seem to pick it up basically the second 2 binds work fine if I remove the :table and add the tablename instead, but I want to use this for more than one table from the same form. The…
easono
  • 15
  • 2
  • 5
1
vote
1 answer

prepared statement using bindValue not working

I'm new to PHP and I'm trying to get a prepared statement to work. Its for my final year project at university and I remember reading that prepared statements are good practice and also good for SQL injections. However the following code gives me a…
Connel
  • 1,844
  • 4
  • 23
  • 36
1
vote
2 answers

Why should I use bindValue / Param vs a normal variable?

I can see many discussions on why is better to use PDO bindValue vs bindValue. But what I could not find was precice information on why should I use that vs a simple variable in the query. Could anyone tell me? thanks $sex = 'male'; $s =…
Jonathan Thurft
  • 4,087
  • 7
  • 47
  • 78
1
vote
2 answers

PHP - PDO problems with bindValue()

I'm writing a class that programmatically creates a table given certain column names. I'm using PDO prepared statements which seem to be causing some problems. Here's the basic procedure: // create a query string to be sent to $pdo->prepare $sql…
nnyby
  • 4,748
  • 10
  • 49
  • 105