Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99090 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87987 invoked from network); 18 May 2017 05:13:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 May 2017 05:13:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@beccati.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@beccati.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain beccati.com designates 176.9.123.236 as permitted sender) X-PHP-List-Original-Sender: php@beccati.com X-Host-Fingerprint: 176.9.123.236 box.beccati.com Received: from [176.9.123.236] ([176.9.123.236:33636] helo=box.beccati.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/DA-21791-36D2D195 for ; Thu, 18 May 2017 01:13:09 -0400 Received: from authenticated-user (box.beccati.com [176.9.123.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by box.beccati.com (Postfix) with ESMTPSA id 79EF3200206; Thu, 18 May 2017 07:13:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=beccati.com; s=mail; t=1495084384; bh=FHLBEM/b7WYlS17RpfYzmhhJa6Jq1+iQLRNj3Ui/tTc=; h=Subject:To:References:From:Date:In-Reply-To:From; b=RyBp9Rt+CNcPKCWwKL4toDvYN6lSswXaVMSiknVHrFsL1OiVjTRPfOz9Dq9KUTrPM jygcsigt7eq6s+cvD53bH9ej8F37AvC95fZBxvdhzGrVeCEqfXDuOHskj6vybiTYfO RaVCQvTK1CM13wPwbHNTX4jaGfzwhgwkWz4SpkZVKiQcDBl2zlyBQzdc5K+EruseCY HVYW9qfq+wqB/s/R0vqG7Tpv6pca2KxgLHh38oieHbu+Xl1ueLb6uz23jaB4kRqZV6 pkfPieSt74O+oojg9k7/tMxNJKbk6leVsB/d3e7wbcE/Lu0zR+uVMx1MTzT/yoFjtI ujC49BuWgzAaQ== To: Dorin Marcoci , internals@lists.php.net References: <002801d2cd97$63921700$2ab64500$@marcodor.com> Message-ID: Date: Thu, 18 May 2017 07:12:58 +0200 MIME-Version: 1.0 In-Reply-To: <002801d2cd97$63921700$2ab64500$@marcodor.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PDO Parameter types // PDO::PARAM_AUTO From: php@beccati.com (Matteo Beccati) Hi Dorin, On 15/05/2017 18:22, Dorin Marcoci wrote: > Currently PDOStatement::bindValue is declared as > > public bool PDOStatement::bindValue ( mixed $parameter , mixed $value [, int > $data_type = PDO::PARAM_STR ] ) > > where third parameter is data type, string type as default. > > It may be useful in terms of providing meta info and handle it accordingly, > like quote, cast or do some additional stuff. > > But there are DBMSes where this "feature" is more a burden than a helper. Please elaborate. > It's because after PDO::prepare, driver and server already knows all > statement parameters and expected types. > > Yes, it can be "forced", saying to pass for a integer parameter a string > value, server will convert it to required type. > > It is convenient in most cases to pass them as strings, for example by > simply assign all params in a cycle before execute. The thing is: the server (with non-emulated prepares) knows the data type it's expecting. PHP has no knowledge of it, so you are expected to do so if the default (string) is not ok. > But when implementing FB Boolean data type parameters and doing ->bindValue > ('bool_param', false) I get an empty string internally. > > Yes, true ZVAL is converted as string as '1', but false as an empty string, > not so consistent here ;) That's not true. $p = new PDO("pgsql:dbname=postgres"); $p->prepare("SELECT ?::bool"); $s->bindValue(1, false); $s->execute(); var_dump($s->fetchColumn());' outputs: bool(false) What are you referring to? > That's why I think, it will be great to have a special type like > PDO::PARAM_AUTO and a config flag to set it as default instead of PARAM_STR. Config flags are evil as it's one more thing you'd need to be aware of and could change depending on the environment you run your script or library on. Cheers -- Matteo Beccati Development & Consulting - http://www.beccati.com/