Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO PARAM_STR and length

Tags:

php

pdo

I don't understand the length option in a PDO PARAM_* statement.

Does the length indicate an amount of required characters, or is it a max?

Example:

$sth->bindParam(2, $color, PDO::PARAM_STR, 12);

Does this require 12 characters, or is this limiting it to 12 characters? Or, am I completely misunderstanding what this is doing?

like image 898
Paul Dessert Avatar asked Aug 31 '12 21:08

Paul Dessert


People also ask

What is PDO :: PARAM_STR?

PDO::PARAM_STR. Represents SQL character data types. For an INOUT parameter, use the bitwise OR operator to append PDO::PARAM_INPUT_OUTPUT to the type of data being bound. Set the fourth parameter, length , to the maximum expected length of the output value.

What is the difference between bindParam and bindValue?

bindParam is a PHP inbuilt function used to bind a parameter to the specified variable name in a sql statement for access the database record. bindValue, on the other hand, is again a PHP inbuilt function used to bind the value of parameter to the specified variable name in sql statement.

What is PDO parameter binding?

The PDOStatement::bindParam() function is an inbuilt function in PHP that is used to bind a parameter to the specified variable name.

What is PDO in database?

PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier. PDO is not an abstraction layer like PearDB. PDO is a more like a data access layer which uses a unified API (Application Programming Interface).


1 Answers

It's an indication of how how much data you wish to receive in the output parameter, the server will not send more than this.

So, to answer your question, it's a limitation rather than a requirement.

like image 135
Ja͢ck Avatar answered Oct 05 '22 12:10

Ja͢ck