Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112622 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57373 invoked from network); 26 Dec 2020 17:44:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Dec 2020 17:44:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 354551804D8 for ; Sat, 26 Dec 2020 09:17:46 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 26 Dec 2020 09:17:45 -0800 (PST) Received: by mail-wr1-f47.google.com with SMTP id m5so6598646wrx.9 for ; Sat, 26 Dec 2020 09:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HE4YPBWj7NVvFqt5grbLZQfOUEn4o8dOwhTp5UBsJK0=; b=Sf09jJqY29vR0DbzadcTFAkyA7SDWsTR3O2zaFy1OHo5oZvMXo9p9gNh5KrAp36mEj 20O6LUJq4NC3F9GReVwzBk2cLZDgfxHRaTO7RRzCP5d56xvoz/mR7PznYwwC1G6s8BTP y69bjFG8DXVhDAToqP5Q9RzzTdmdXAgqrjvNM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HE4YPBWj7NVvFqt5grbLZQfOUEn4o8dOwhTp5UBsJK0=; b=qcZ55EIAATT85+ZTwbFGhkIaRK50RplcCv/oEpqzfWc+Dty8wuReaDdXXfsnfwd+Jt 1+aQ+cVcYVicfEpZtHfZFqHj8z69infaldEURSKtqLf4Sq4a+g/0gdVrLjIq4AJOHAo8 N3F5jE+totUu7+DNEg5OQZPBCvZYEX2kGgOrxhb0x83d1GSLg238c3NQVIOeMklYaGmv +yL+8F7hmopfgACqWokAny00rp+rGpNunJ7nPWbrR96xTkDL/CkPh7cubSXrep8ErunX 2/sxF6Cby/c6WwWbjECJOgje556iO0F/VTfdt5ZehSfMJz+cz7kQdaRw9bW6gNz+xFwz DaGw== X-Gm-Message-State: AOAM530cGTQA1EXJYB8yFCTpkxVgkL+oFvUQY0dGqgdchFWl+eamsntD pnQrR6a6VhHzSFQ2ng4p4hj7BJDvbBfOXXjKrrdp4A== X-Google-Smtp-Source: ABdhPJyt7F6gOKWGBwmjGLbVVyU43jRVcZLGS4c1BO1c9d8sjCOF9wtebEySJ+ZijvrTcnIDHnUEP06wHj/WzFyACAc= X-Received: by 2002:a5d:4a4e:: with SMTP id v14mr43130837wrs.80.1609003064486; Sat, 26 Dec 2020 09:17:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 26 Dec 2020 17:17:33 +0000 Message-ID: To: Kamil Tekiela Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000019fab405b761383b" Subject: Re: [PHP-DEV] Making mysqli easier to use with parameterised queries From: craig@craigfrancis.co.uk (Craig Francis) --00000000000019fab405b761383b Content-Type: text/plain; charset="UTF-8" Hi Kamil, Thank you for your initial thoughts, adding the syntax highlighting, and the suggestion to use the splat operator, it's really appreciated. Good to know about mysqli_execute() not actually being deprecated, I'll try to think of a different name, maybe mysql::run(), to keep it short (suggestions welcome). It's a shame supporting both libraries would be tricky; I'd like to avoid an argument about dropping support for libmysql client (tbh, I'm not sure what the advantages are, maybe automatic reconnect? licensing?). With binding type guessing, that can be removed, 's' is fine for most values. I'm just going on the basis that a provided integer could stay as an integer as it's sent to the server. My limited understanding is that it would save a few bytes in the request; might avoid some type conversion issues (int>string>int); and, if an integer was provided for a text field, the MySQL server can do the conversion anyway. As to the state of mysqli code being written (and similar issues), I do have an idea on how to fix, but that's a bit more of a long term thing (where I need to convince everyone it's worth it), and I need the "right way" to be so much easier to do. Thanks again, Craig On Sat, 26 Dec 2020 at 15:13, Kamil Tekiela wrote: > Hi Craig, > > This is a great proposal, and I am delighted that someone is still > interested in mysqli and wants to improve it. I will discuss the > proposal below, but first some notes about the RFC itself: > 1. mysqli_execute() is not deprecated despite what the PHP manual said > for the past 14 years. It is just an alias of mysqli_stmt_execute(). > It's beyond me why we even have a separate page in the manual for that > alias. The mysqli documentation is in such a bad state that there are > lies/problems pretty much on every page. > 2. Introducing mysqli::execute() would be a great idea, but the name > would be terribly confusing with mysqli_stmt::execute(). We need a > better name. > 3. Please use syntax highlighting. I have already added that for you. > > I like the proposal, and I think that having a shorthand notation for > prepared statement for one-time execution is a brilliant idea. The > implementation would not be too difficult, but it would obviously work > with mysqlnd only. This in itself is a problem. Ideally, we should > drop support for libmysql client but apparently some people think it > is still useful. We could emulate the same for libmysql but that would > make the implementation more complex. > Your implementation example in PHP has a major problem. The binding > types should never be guessed based on the value. The type is > specified by the column definition. Guessing the type will lead to > very undesirable behaviour. 99.99% of the time the values should be > bound as strings. If an explicit type cast needs to be performed by > mysqli then the long-way can be used instead. > Also, rather than binding the variables by reference explicitely, you > can use splat operator. This makes the implementation in PHP much > simpler: > > class mysqli_rfc extends mysqli { > function execute($sql, $parameters = []) { > // Preparing... > $statement = $this->prepare($sql); > // Binding... > if ($parameters) { > $statement->bind_param(str_repeat("s", > count($parameters)), ...$parameters); > } > // Executing... > $statement->execute(); > > // Fetching mysqli_result or null (only with mysqlnd) > return $statement->get_result(); > } > } > > In C code, this could be easily achieved by creating a function that > is just a mash-up of all 4 of these functions. I think this would > definitely be a nice addition to mysqli, even though I doubt that it > will improve the state of mysqli code written by people. After all, we > can't force them to use parameter binding. > > Regards, > Kamil > > On Sat, 26 Dec 2020 at 11:23, Craig Francis > wrote: > > > > Hi, > > > > Could the mysqli extension be tweaked to make parameterised queries > easier? > > > > I've started an RFC at: > > > > https://wiki.php.net/rfc/mysqli_execute_parameters > > > > I'm going on the basis that some developers use mysqli directly, often > > because they want a small stand-alone script that has no dependencies, > and > > the current mysqli extension doesn't exactly help them make the right > > choices. > > > > Craig > --00000000000019fab405b761383b--