ПІДТРИМАЙ УКРАЇНУ ПІДТРИМАТИ АРМІЮ
Uk Uk

New in PHP 8.2: mysqli_execute_query / mysqli::execute_query

New in PHP 8.2: mysqli_execute_query / mysqli::execute_query

Nice innovation in the mysqli and in PHP 8.2: mysqli execute_query

In continuation of my previous article , I want to write about another nice innovation in themysqlimodule.

Since PHP 8.2.0 there is a new functionmysqli_execute_queryormysqli::execute_queryif you prefer object-oriented style.

This is a really nice feature. It allows you to kill two (three) birds with one stone:

  • generate a prepared statement
  • execute it by substituting values ​​from the array of variables
  • retrieve query result as associative array

Let's try this in practice:

<?php
$query = 'SELECT Name FROM City WHERE District=? ORDER BY Name LIMIT 5';

/* here the magic */
$result = $mysqli->execute_query($query, ['Nordrhein-Westfalen']);

foreach ($result as $row) {
 printf("%s \n", $row["Name"]);
}

You can try this code here: phpize.online 

Теги #php #mysql #news
Ресурс : dev.to


Scroll to Top