Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99116 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14530 invoked from network); 19 May 2017 10:25:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 May 2017 10:25:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=adam.baratz@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=adambaratz@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.175 as permitted sender) X-PHP-List-Original-Sender: adam.baratz@gmail.com X-Host-Fingerprint: 209.85.216.175 mail-qt0-f175.google.com Received: from [209.85.216.175] ([209.85.216.175:36837] helo=mail-qt0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/E7-23431-228CE195 for ; Fri, 19 May 2017 06:25:38 -0400 Received: by mail-qt0-f175.google.com with SMTP id f55so54434968qta.3 for ; Fri, 19 May 2017 03:25:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=38eUXcjq6a/VfllVjn+e1MslpTVVPx36jU3wR14w+xg=; b=M7qh00UdQq2BhWpsqr/FTjkE3ouL4SqynJCzO1pA/x7H/8wSUz/pJxSdbvme47OS9P jYbi7gIOhLJtZOkNhaZPwZTar37O4m4M2dTco8ug4LuVk0XudWxcuY+TWsJy8sZ8RorY 5Bzu8p+kBoUJAhaaH4QgJBe3a6D3Zrs0WEldpaM4sMcH2GcaduUVDTfMTOSq7ZdfANq+ urIdOJrmkfChhBFvSJOZXD8d06a92VCZ1d4FmgI33URzy9t07f6vkLEIoIR8t2gRQrxl j3TnSZE9hfwRuvfh8RwQQl14YKIaGCBoMhtyBlbOqE+YdBuKZWOcWLnLq/6pqRFD6RTM Jg5Q== X-Gm-Message-State: AODbwcBkmf5+qySBksOI1u0tFMGuwF858Lop5OBP1sNtW1NiqtoNYevY 0BZoyKa/V1KA7rXKeHc= X-Received: by 10.200.46.10 with SMTP id r10mr7878814qta.290.1495189535483; Fri, 19 May 2017 03:25:35 -0700 (PDT) Received: from mail-qk0-f175.google.com (mail-qk0-f175.google.com. [209.85.220.175]) by smtp.gmail.com with ESMTPSA id 83sm5767143qkq.26.2017.05.19.03.25.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 03:25:35 -0700 (PDT) Received: by mail-qk0-f175.google.com with SMTP id u75so57135144qka.3 for ; Fri, 19 May 2017 03:25:35 -0700 (PDT) X-Received: by 10.55.15.143 with SMTP id 15mr7636631qkp.44.1495189534873; Fri, 19 May 2017 03:25:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.152.27 with HTTP; Fri, 19 May 2017 03:25:34 -0700 (PDT) In-Reply-To: <000601d2cff3$bbffc5f0$33ff51d0$@marcodor.com> References: <000601d2cff3$bbffc5f0$33ff51d0$@marcodor.com> Date: Fri, 19 May 2017 12:25:34 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Dorin Marcoci Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="001a1146cc101926b6054fddf13f" Subject: Re: PDO Parameter types // PDO::PARAM_AUTO From: adambaratz@php.net (Adam Baratz) --001a1146cc101926b6054fddf13f Content-Type: text/plain; charset="UTF-8" > > > The risk with this is queries could lose portability between drivers. > There are differences in the level of information each one can get from the > DB server, and different costs associated with asking. > > I think the right model is to have PDO types map directly to SQL types. > That said, the code and documentation don't take a strong stance on how > types should work. And there's not a lot of agreement in the community, at > least as indicated by discussions on this list. > > Yes, agree about portability. But from other side, it will be a great > benefit for drivers that supports server side prepares, not just emulation. > > Maybe even a better way is just to change default param type from > PARAM_STR to PARAM_AUTO in bindValue family routines, without any driver > options or configs. > So if drivers supports server prepares with type hinting, OK: treat it > better, if not, push it as a string like is now. > Anyway, there is not a documented standard what driver should do when you > pass something like bindValue('param', '', PDO::PARAM_BOOL) or > bindValue('param', 't', PDO::PARAM_BOOL) or bindValue('param', '0', > PDO::PARAM_BOOL) > In case if data type is specified, then force it, as dictate the php code. > > What do you think? > I'm not sure that changes the proposal too much. My position is still that I'd like PDO to be less "magical," to put more of the burden on providing the right content to the user. Much of PHP internals are about providing a light layer on a third-party library (in this case, all the DB libraries). You can then compose them as needed to get the right functionality for your application. We get a lot of power and flexibility from that. Making APIs that are too "opinionated" makes it harder for users to control their destiny. I haven't tested this, but I think you could implement the functionality you need in userland. You could write a class like this: class MyPDOStatement extends \PDOStatement { public function bindValue($parameter, $value, $data_type = -1) { // or define a const somewhere for an AUTO type if ($data_type == -1) { switch (gettype($value) { case 'boolean': $data_type = \PDO::PARAM_BOOL; break; default: $data_type = \PDO::PARAM_STR; break; } // and add any other cases you care about } return parent::bindValue($parameter, $value, $data_type); } } Then when you construct a new \PDO instance, set a \PDO::ATTR_STATEMENT_CLASS option referring to that class. There are some examples in ext/pdo/tests, or you can look at the implementation of \PDO::prepare() for the nitty gritty. I think this hook is a good example of the principle I was describing. PDO may only have a basic set of tools, but it makes it easy to extend according to your preferences. Hope this helps, Adam --001a1146cc101926b6054fddf13f--