note 130383 added to mysqli-stmt.fetch

From: Date: Sat, 21 Jun 2025 20:53:31 +0000
Subject: note 130383 added to mysqli-stmt.fetch
Groups: php.notes 
Request: Send a blank email to php-notes+get-222234@lists.php.net to get a copy of this message
<?php // This is my simple way to load an unique data. // Load cliente - return my cliente id,nome and email. // Connect to Mysqli $mysqli = new mysqli("localhost", "my_user", "my_password", "clientes"); // Prepare your query $stmt = $mysqli->prepare("SELECT id, nome, email FROM clientes WHERE id = ?"); // Set your cliente id to load $id = 1; $stmt->bind_param('i', $id); // Execute your query $stmt->execute(); // Get result $result = $stmt->get_result(); // Fetch table fields (id,nome and email) $fields = $result->fetch_fields(); // Fetch your rows into array $rows = $result->fetch_array(); $data = array(); // Combine the fields of your table with your rows array result. foreach($fields as $field) { $data[$field->name] = $rows[$field->name]; } // Close the dataset $stmt->close(); // Debug to see data return echo "<pre>"; print_r($data); echo "</pre>"; // I hope I helped! // Julio Leles (julio.necronomicon@gmail.com) ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 2804:14c:5b80:8141:f97f:6b45:e6db:5a15) ---- Manual Page -- https://php.net/manual/en/mysqli-stmt.fetch.php Edit -- https://main.php.net/note/edit/130383 Del: integrated -- https://main.php.net/note/delete/130383/integrated Del: useless -- https://main.php.net/note/delete/130383/useless Del: bad code -- https://main.php.net/note/delete/130383/bad+code Del: spam -- https://main.php.net/note/delete/130383/spam Del: non-english -- https://main.php.net/note/delete/130383/non-english Del: in docs -- https://main.php.net/note/delete/130383/in+docs Del: other reasons-- https://main.php.net/note/delete/130383 Reject -- https://main.php.net/note/reject/130383 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222234) next »