In PDO, is there a performance difference if int is quoted as a string?

Is there a performance difference if an integer is bound as a string in a prepared PDO request? In Mysql, queries work either if the value is bound as an int or a string, but is there a difference in performance or any errors in doing so?

$pdo = new PDO(
    "mysql:host={$host};port={$port};dbname={$dbname};charset=utf8", 
    $username, 
    $password
);
$statement = $pdo->prepare("SELECT * FROM `table` WHERE `id` = :param");

// Is there any performance difference between the two rows below
$statement->bindValue(":param", 5);
$statement->bindValue(":param", 5, PDO::PARAM_INT);

$statement->execute();

Is there a difference between binding a parameter and specifying its type or just quoting it as a string?

+4
source share
2 answers

If you want to accept it exactly, the method in which you specify the type is slightly faster than where you do not specify the type, and the default type is PDO::PARAM_STR.

If you run it 1 million times, then avarage will be as follows:

  • int type: 0.53 seconds ( $stmt->bindValue(":param", 5, PDO::PARAM_INT);)
  • : 0,66 ($stmt->bindValue(":param", 5);)
  • str type sepcified: 0.70 ($stmt->bindValue(":param", 5, PDO::PARAM_STR);)

PHP 5.6.3; 32- Windows;

+6

, . MySQL ( ).

, PDO:: PARAM_STR , PDO:: PARAM_INT. PDO:: PARAM_STR .

, .

0

All Articles