___ ___ erkimt What exactly does the method PDOStatement :: bindColumn ()? ______ qstntxt ___

This method is for database manipulation. I'm not understanding exactly what it does in the column / variable.

    
______ azszpr125912 ___

Used to assign the value of a column of your Select to a variable.

Note that there is a very detailed explanation in the documentation, but to understand you must be familiar with "passages by reference."

See:

%pre%

All the variables passed to the second bindColumn parameter will have the previously specified column value.

In this case, when we make %code% , the variable %code% is created and passes internally to the value of that column, each time the %code% is rotated.

Note that in the third call of %code% in the example, the name of the column where you want to "bind" (reference or pointer) the value for a variable is used.

Note that the second argument of %code% is a reference, so it has the values assigned according to the %code% call.

%pre%

For a better understanding, the functions that have this %code% sign in the argument require a variable, so that additional values can be returned, since %code% is returned something different.

For example, it is the %code% function, which returns a %code% . In it, you can pass two parameters by reference to know what the error or error code is.

%pre%

That is:

%pre%     
___

1

This method is for database manipulation. I'm not understanding exactly what it does in the column / variable.

    
asked by anonymous 29.04.2016 / 03:00

1 answer

2

Used to assign the value of a column of your Select to a variable.

Note that there is a very detailed explanation in the documentation, but to understand you must be familiar with "passages by reference."

See:

 $sql = 'SELECT nome, idade, cpf FROM fruit';
  try {
    $stmt = $dbh->prepare($sql);
    $stmt->execute();

    // Atribuição pela posição da coluna
    $stmt->bindColumn(1, $nome);
    $stmt->bindColumn(2, $idade);

    // atribuição pelo nome da coluna

    $stmt->bindColumn('cpf', $cpf);

    while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
      $data = $nome . "\t" . $idade . "\t" . $cpf . "\n";
      print $data;
    }
  }
  catch (PDOException $e) {
    print $e->getMessage();
  }

All the variables passed to the second bindColumn parameter will have the previously specified column value.

In this case, when we make bindColumn(1, $nome) , the variable $nome is created and passes internally to the value of that column, each time the while is rotated.

Note that in the third call of bindColumn in the example, the name of the column where you want to "bind" (reference or pointer) the value for a variable is used.

Note that the second argument of bindColumn is a reference, so it has the values assigned according to the fetch call.

public bool PDOStatement::bindColumn ( mixed $column , mixed &$param [, int $type [, int $maxlen [, mixed $driverdata ]]] )

For a better understanding, the functions that have this & sign in the argument require a variable, so that additional values can be returned, since return is returned something different.

For example, it is the fsockopen function, which returns a resource . In it, you can pass two parameters by reference to know what the error or error code is.

 resource fsockopen($host, $port, &$err_no, &$err_str);

That is:

 $handle = fsockopen($host, 80, $err_no, $err_str);

 if ($handle === false) {
      throw new Exception($err_str);
 }
    
29.04.2016 / 04:23