Hướng dẫn bindvalue trong php

Chuyển đến nội dung chính

Trình duyệt này không còn được hỗ trợ nữa.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

PDOStatement::bindValue

  • Bài viết
  • 09/09/2022
  • 2 phút để đọc

Trong bài viết này

Download PHP driver

Binds a value to a named or question mark placeholder in the SQL statement.

Syntax

  
bool PDOStatement::bindValue[$parameter, $value[, $data_type]];  

Parameters

$parameter: A [mixed] parameter identifier. For a statement using named placeholders, use a parameter name [:name]. For a prepared statement using the question mark syntax, it is the 1-based index of the parameter.

$value: The [mixed] value to bind to the parameter.

$data_type: The optional [integer] data type represented by a PDO::PARAM_* constant. The default is PDO::PARAM_STR.

Return Value

TRUE on success, otherwise FALSE.

Remarks

Support for PDO was added in version 2.0 of the Microsoft Drivers for PHP for SQL Server.

Parameter example

This example shows that after the value of $contact is bound, changing the value does not change the value passed in the query.

  

Note

It is recommended to use strings as inputs when binding values to a decimal or numeric column to ensure precision and accuracy as PHP has limited precision for floating point numbers. The same applies to bigint columns, especially when the values are outside the range of an integer.

Decimal input example

This code sample shows how to bind a decimal value as an input parameter.

Bài Viết Liên Quan

Chủ Đề