Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109228 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11587 invoked from network); 23 Mar 2020 13:55:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Mar 2020 13:55:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 43AA8180503 for ; Mon, 23 Mar 2020 05:19:42 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.64.0.0/10 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2065.outbound.protection.outlook.com [40.107.223.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 23 Mar 2020 05:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PLfL5y+K9izTmRaZ/RH+dD4U7NLXmULqiRGMtSIDL0IYqe+dWai9LTLf9O75K4mVsGYPQswSxXurNdccyoIkmuQAraCvnCtNa+DwbGzboTP1peRvVfqCky8dzYw3NCq2mFWZ/4coBCQjdDV2EbiT5ANllI8DRHuFsnPi+iv3a/2W89jNXHJ42c9UDwYODj3RsXyDuAm5OByDzCE0cRS/s+oyt5sAuTMy4NMSi6WgOlYjyxJW0MDtVwb/+uc8UmiDy5obcfy83HQ2BlHefAl14bGzWek2SwYzgIu92cUpwSVGdVJZF1KSjNUGjPAMMbULQpfIYB51qNymMD+jQ8FeqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b+aWWB6UU3mVC54ehjd8k5Kgx9BTERlq03nRY425wgo=; b=j8cIQ/njeNfpFpuX1JiiTuipZoaGG4AILrjBTWMqfka7oTDRWCikfvtkRuEdm/iFxXUFj/DEopjlXaL7u7ScjRZBWuimsNuOHfe8krLpF6/FU3E+26MQsD7OYM4PQqwsSi9gjouW304isWTTwWHIn10GyqoBYRqKaOsaosQVaYbWauFeQFrQe7Hmx26Z51w5n6BG1GGkrDBvcN90pv8Kx1EaWTjT6ohV5GiApozrM7oyZt67RLBqn8hfncbqxUn0QO+I8/ucQ/dwN+JAIxWot3IHvWIT+0gxhLLW0l6DrF0uFg19ws1aFC6aegB1VB3zwXtopXw2VMG9q4qOK6YpNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=onlinecommercegroup.com; dmarc=pass action=none header.from=onlinecommercegroup.com; dkim=pass header.d=onlinecommercegroup.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=appriver3651009564.onmicrosoft.com; s=selector2-appriver3651009564-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b+aWWB6UU3mVC54ehjd8k5Kgx9BTERlq03nRY425wgo=; b=D4FQDA4LdKazOrxe4y2SFMHK/qpEA+b8WNPztv8csFSA4cZl5fGjXlxpuTKmm9DXANTRb753638X0nRLOOmNZ+aHOKntca06EyXZL4RzpxVHZQow7j1IPc2DRStM7oWQfUF834LEZPEdrP/xiFl2W/To25WBIy6Zb0hqfUJb058= Received: from BN8PR18MB2724.namprd18.prod.outlook.com (2603:10b6:408:a2::23) by BN8PR18MB2577.namprd18.prod.outlook.com (2603:10b6:408:9f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20; Mon, 23 Mar 2020 12:19:38 +0000 Received: from BN8PR18MB2724.namprd18.prod.outlook.com ([fe80::a5f3:38c2:c18b:538c]) by BN8PR18MB2724.namprd18.prod.outlook.com ([fe80::a5f3:38c2:c18b:538c%4]) with mapi id 15.20.2835.021; Mon, 23 Mar 2020 12:19:38 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] Making mysqli easier to use with parameters Thread-Index: AQHWAEfNiOygEIXUHkiL3tGqAolHVahUvIGAgACHigCAANThUA== Date: Mon, 23 Mar 2020 12:19:37 +0000 Message-ID: References: <3CE6E742-33E9-4686-93C4-2B1DB1E405B7@craigfrancis.co.uk> <10B08096-5A36-4F69-B60F-3CCC8AF7F66D@craigfrancis.co.uk> In-Reply-To: <10B08096-5A36-4F69-B60F-3CCC8AF7F66D@craigfrancis.co.uk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Joel.Hutchinson@onlinecommercegroup.com; x-originating-ip: [71.12.136.26] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c760cc38-4083-40da-f66a-08d7cf2474c7 x-ms-traffictypediagnostic: BN8PR18MB2577: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 0351D213B3 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(346002)(39830400003)(396003)(376002)(136003)(199004)(15188155005)(26005)(966005)(186003)(6916009)(6506007)(16799955002)(8936002)(81166006)(81156014)(8676002)(7696005)(53546011)(86362001)(52536014)(33656002)(76116006)(64756008)(66556008)(55016002)(316002)(5660300002)(66476007)(71200400001)(508600001)(9686003)(66946007)(66446008)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN8PR18MB2577;H:BN8PR18MB2724.namprd18.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1; received-spf: None (protection.outlook.com: onlinecommercegroup.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3fLPgSrTcOGVb/IXB9Cs89O63S4lB4FBAZISizT5VcBp7OpyqDdQWDoo5fetzOIgcN3oNe/eAEE1MSSI8HnC2RnryUUR2zqwOR8/DKJ29LZHMbe5nWQH+c6N/+M3w3VeI1IXiCe7g193C1zhxUSFjKv5W0Tl2aI8iYoNZBd9h4srHwSKxUcUECBuUhhN1W0Dmbr3NfQu63uWAplel/Alj0X1THb5jNLE2W8gh/Qsf3FKt+E+b/n3dNjvIAwUv+KzXOZizF1Y8zIkRy2BCZKcmBQxOW396w6+tRw4mhFj/vvsnqFzGsq5+wJeOtsK6oxffOsn55qU8f09WMcnDEpd4D1LOm08wtur4pfsRcI8b0aGFvX2fHPP0WkDc2Q7XKp2kh7dK9/WMAjE1MMycYb4++OUYj1Y2np8XaGegyZEqoPq/ZCw3aAdNxebXOekTWcZQNoeeU474mdxkUS/6bbr8xMHovWFWAqfvJxBquqchWZsA4XeCEEl6jjzRJUCUmAJ4LOVckl9mawP4lrz0Fp2/Q== x-ms-exchange-antispam-messagedata: btfZHgwLQwFzrfLcP76z1hKqN8YP/0koAw+yx4QvvM4mgsZVPGpJL1yMJ4rAJc1HYlYRAB/MSC4UnGpMQ4jhzhTVSrkTOBedD0Y/zV/kG7t52yKJpCwukh2QOnJVjXgicdelhFCGToxCe2gqeiPS6w== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: onlinecommercegroup.com X-MS-Exchange-CrossTenant-Network-Message-Id: c760cc38-4083-40da-f66a-08d7cf2474c7 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Mar 2020 12:19:38.0089 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 733bee1d-43aa-48a2-a713-34870bf1749b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +Ga4hWR6/Y7wKYSV716d/niEXiYR80GDtCuotRRY/TYuC/zPVmZOJFJvNyJ0UeXf X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR18MB2577 Subject: RE: [PHP-DEV] Making mysqli easier to use with parameters From: Joel.Hutchinson@onlinecommercegroup.com (Joel Hutchinson) Hey Craig, I think this might be in the same vein as something I'd love to = see done (PDO already does this). Proposed it a while back and have talked = to a few internals folks about it off and on https://externals.io/message/107857#107857 Either way, mysqli lacks any proper way to do dynamic binds on a single bas= is. This seems like low hanging fruit to make mysqli easier to use -----Original Message----- From: Craig Francis =20 Sent: Sunday, March 22, 2020 6:34 PM To: Levi Morrison Cc: PHP internals Subject: Re: [PHP-DEV] Making mysqli easier to use with parameters On 22 Mar 2020, at 15:28, Levi Morrison wrote= : > applying the ids array as `...` will handle the by-reference passing. That does help, thanks. But I still wonder if the ability to pass in a single array of parameters t= o `$statement->execute()` would remove a step, and be a bit easier to use f= or all queries. If this was for a search form, where it dynamically creates a SELECT with a= variety of different parameters, it gets tricky again. And there was the thing I tacked onto the end, where I would like to use a = `$statement->result` property to skip the use of `$statement->get_result()`= : while ($row =3D mysqli_fetch_assoc($statement->result)) { } Craig > On 22 Mar 2020, at 15:28, Levi Morrison wro= te: >=20 >> >=20 >> $in_sql =3D implode(',', array_fill(0, count($ids), '?')); >>=20 >> $sql =3D 'SELECT id, name FROM user WHERE id IN (' . $in_sql . ')'; >>=20 >> if ($statement =3D $db->prepare($sql)) { >>=20 >> $params =3D [str_repeat('i', count($ids))]; >> foreach ($ids as $key =3D> $value) { >> $params[] =3D &$ids[$key]; // Must be a reference, not ideal. >> } >> call_user_func_array(array($statement, 'bind_param'),=20 >> $params); >>=20 >> $statement->execute(); >>=20 >> $result =3D $statement->get_result(); >>=20 >> while ($row =3D mysqli_fetch_assoc($result)) { >> print_r($row); >> } >>=20 >> } >>=20 >> ?> >=20 > Written in my email client without error handling code, so apologies=20 > if it's not quite correct: >=20 > $in =3D join(',', array_fill(0, count($ids), '?')); > $select =3D "SELECT id, name FROM user WHERE id IN ({$in});"; > $statement =3D $mysqli->prepare($select); > $statement->bind_param(str_repeat('i', count($ids)), ...$ids); > $statement->execute(); >=20 > This is part of my [highest score answer on StackOverflow][1]. > Critically, applying the ids array as `...` will handle the=20 > by-reference passing. >=20 > I don't think we need to improve the ergonmics of mysqli for this case=20 > specifically, as it's always going to require some dynamic SQL=20 > generation because of the variable number of parameters to bind. >=20 > [1]: https://stackoverflow.com/a/23641033/538216 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:= http://www.php.net/unsub.php