php - Drupal 8 PDO Prepared Statements bindValue error -
i having trouble query. query results in following error.
pdoexception: sqlstate[hy093]: invalid parameter number: no parameters bound
$sql = "insert ignore table set user_id = :uid"; if ($con = $connection->prepare($sql)) { $con->bindvalue(':uid', intval($this->uid), pdo::param_int); $con->debugdumpparams(); $con->execute(); }
parameters
params: 1 key: name: [4] :uid paramno=-1 name=[4] ":uid" is_param=1 param_type=1
query works.
$sql = "insert ignore table set user_id = :uid"; if ($con = $connection->prepare($sql)) { $con->execute([':uid' => intval($this->uid)]); }
question why can't bind parameter or value pdo prepared statement?
i using drupal 8 , believe connections replace pdo default driver.
drupal 8 replaces default pdo driver custom driver drupal uses insert, update, prepare statements, ect... these drivers override default operations. if want complete customize query need set own connection separate drupal , use that.
$dsn = 'mysql:host=localhost;dbname=drupal'; $username = 'username'; $password = 'password'; $connection = new pdo($dsn, $username, $password);
then using custom queries work. , won't no parameters bound error
Comments
Post a Comment