Now, many recommend to use the new MySQLi extension for database queries, which promises support of all new features, more conveniences and more high-speed operation.
One thing I wonder: why such a "new" and "cool" the extension did not come up with a method that allows you after executing prepared statements in advance to an unknown number of fields? I mean a sample:
SELECT * FROM table;
In the preparation function of the result of the expression is not even possible to pass a single variable-the array keys and values to which would be the result of sampling.
As a result, if we have a table of the form:
Field | Type |
---|
id | INT(10) |
field1 | VARCHAR(20) |
field2 | VARCHAR(20) |
then when you query:
$stmt = $mysqli->prepare("SELECT * FROM table WHERE id = ?"); $stmt->bind_param('i', $itemid); $stmt->execute(); $stmt->bind_result($id, $field1, $field2); $stmt->fetch();
everything will be fine. But if we add in table one more field, as this code will cause a critical error from the disparity between the number of variables and fields.
Why is it done?