|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #68470 Wish:Add prefix to field name while mysqli_result::fetch_object
Submitted: 2014-11-21 10:47 UTC Modified: 2017-05-15 09:36 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: eglic dot csdn at gmail dot com Assigned:
Status: Open Package: MySQLi related
PHP Version: 5.6.3 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: eglic dot csdn at gmail dot com
New email:
PHP Version: OS:


 [2014-11-21 10:47 UTC] eglic dot csdn at gmail dot com
I tought to improve fetch_object such as follow code is useful:

mysqli_result::fetch_object ([ string $class_name = "stdClass" [[, string $field_name_prefix = ''], array $params ]] )

example code :

$result = $mysqli->query("select id,name from user limit 1");
$user = $result->fetch_object('stdClass','__');

output :

object stdClass {
  $__id = 1;
  $__name = 'someone';

in addition , i have a question :
 why call __constructor at the last in this method?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-15 09:01 UTC]
-Status: Open +Status: Feedback
 [2017-05-15 09:01 UTC]
Can you provide some more use cases for this suggestion? Can you also sketch some specification detail for it? Also, sorry but I do not understand you question, perhaps try stackoverflow.
 [2017-05-15 09:36 UTC] eglic dot csdn at gmail dot com
-Status: Feedback +Status: Open
 [2017-05-15 09:36 UTC] eglic dot csdn at gmail dot com
NOT stdClass. for example :
class UserEntity {
  function __construct(){
    $this->name = '';   // Default value from mysql schema
    $this->status = 1;  // default value from mysql schema

  public $name;

  public $status;

Scene 1:
  $u = new UserEntity();
  $u->name = 'test';
  $u->status = 0;

  this is correct.
Scene 2:
   $u = $result->fetch_object('UserEntity');

  output :
    $u->name is '';
    $u->status is 1;
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 07:05:45 2022 UTC