Questions tagged [bindparam]

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

Binds a PHP variable to a corresponding named or question mark parameter in the SQL statement that was used to prepare the statement. Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

public bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )

Reference

PHP Documentation

267 questions
2
votes
2 answers

What mysqli value for bind_param() i or s

I am using mysqli bind_param() when I'm inserting stuff to my DB. When I tried to insert a phone number as "0737327373" the value got inserted as "737327373" without the leading "0". But when I changed bind_param("i", $phoneNumber) to…
user2722667
  • 8,195
  • 14
  • 52
  • 100
2
votes
1 answer

Custom mysqli prepare function

I'm doing my first own database class at the moment and currently I'm doing the prepare function. What this function does is to take in an SQL-query and then an array containing the variables for the statement. I'm having problems with binding the…
William Boman
  • 2,079
  • 5
  • 26
  • 39
1
vote
0 answers

php PDO bindParam using empty string

I'm not sure about this behaviour. $query = 'INSERT INTO XXX (row1) VALUES (:myparam)'; $stmt = $mycon->prepare($query); $stmt->bindParam(':myparam','',PDO::PARAM_STR); above code will fail at third line. When I use following code, everything works…
1
vote
1 answer

PHP PostgreSQL PDO can't bind parameter with LIKE

Using PHP PDO to attempt a simple search for term in database. The error return implies that PDO can't determine the param type. I'm explicitly specifying it as STR when binding it and also casting it to varchar in the query string. The query…
raw-bin hood
  • 5,839
  • 6
  • 31
  • 45
1
vote
0 answers

Why does bind_param work when my prepared statement doesn't have any placeholders?

I ran across something I'm not sure on why it is working. Below I use bind_param and I forgot to set the proper parameter types but somehow it works. By working I mean that the results I get are that the data retrieved is correct. Look at returned…
deathismyfriend
  • 2,182
  • 2
  • 18
  • 25
1
vote
1 answer

Do we need to test the return value of bind_param when building prepared statements in PHP?

Linked question is here. I have upgraded the code in the linked question to use a prepared statement. I now have: $stmt = $conn->prepare("INSERT INTO `workbook-data` (`workbook-language`, `gui-language`, `foreign-language-group-mode`, `version`)…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
1
vote
1 answer

Can I use string ("sss...") for all the values in bind_param() type? If no, why not?

I am making a method in my class, where the parameters for the method are $sql, $types, $values . function getResult($sql, $types, $values){ $stmt = $this->conn->prepare($sql); $stmt->bind_param( "$types" , ...$values); …
Chirka
  • 31
  • 4
1
vote
3 answers

SqlAlchemy with list in where clause

my table in a database is as follow Username city Type Anna Paris abc Marc london abc erica rome AF Sara Newyork cbd silvia paris AD I have a list contains string…
khaoula
  • 67
  • 1
  • 8
1
vote
1 answer

Why doesn't Prepared Statment work properly?

I have an insert on my page with BindParam, and I have noticed that sometimes the post arrives either empty or with half the text, does anyone know whether it may be due to a special character or does someone know the problem? I'm still learning,…
user11322597
1
vote
1 answer

Solution to bind 2+ arrays as params in MySQL prepared statement?

I was able to bind 1 array as a parameter no problem. However, I am trying to bind 2+ arrays as parameters and its not going over so well. I keep getting an error that I cannot use positional arguments after unpacking. How do I combine the arrays as…
1
vote
1 answer

PHP bind_param save number as i or s what difference does it make?

When we do PHP prepare statement, we need to specify bind type such as i, s, d, b. What difference does it make if I bind a number as "s" string?
Wayne
  • 13
  • 2
1
vote
2 answers

Using s for int in bind_param

Let's take this mysqli query: $query = "SELECT * FROM table WHERE (".$id_type."=?)"; $id_type is hard-coded and can be "userID" (int(11) in the mysql table) or "sessionID" (char(36) in the mysql table). Can I just bind the parameters like…
binoculars
  • 2,226
  • 5
  • 33
  • 61
1
vote
2 answers

Using mysql's INTERVAL with prepared statement

I prepare my DB request for prevent SQL injection with the extension Mysqlnd. A request like this work on my site : SELECT a, b FROM table where a = ?; This next request doesn't work on my site: SELECT a, b FROM table where b >…
Clément M
  • 43
  • 4
1
vote
2 answers

How do I determine datatype of input values that am getting from my html form so that I can use them to bind parameters in prepared statement

I want to dynamically determine the data type of input values I am getting from my HTML input form.this will assist me to bind parameter values of data I am inserting into my database using PHP. This information will assist me to determine the…
1
vote
1 answer

Why is prepared statement failing on bind_params?

I'm using prepared statements to add rows to my database. I'm restructuring my code and am running into an issue with bind_param - I assume it's syntactical but can't figure out what's wrong. No data supplied for parameters in prepared…
froggomad
  • 1,747
  • 2
  • 17
  • 40