Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:08:25+00:00 2026-06-18T04:08:25+00:00

Hi I am trying to store MySQL result into a global array class db

  • 0

Hi I am trying to store MySQL result into a global array

class db
{
 function CustomLoad($table_name,$Fields)
  {
     global $_MYSQL_DATA;

     $_MYSQL_DATA=array();

     $qry = mysql_query("SELECT * FROM $table_name") or die(mysql_error());
     while($row = mysql_fetch_assoc($qry))
     {
       foreach($Fields as $r=>$key)
       {

        $_MYSQL_DATA[$r] = $row[$r];
       }

     }

   }
}

I am calling like this

$dbObj = new db();
$fields = array("FIELD_1"=>"FIELD 1","FIELD_2"=>"FIELD 2","FIELD_3"=>"FIELD  3","FIELD_4"=>"FIELD 4");
$dbObj->CustomLoad("registrations",$fields);

print_r($_MYSQL_DATA);

The problem is I am getting the last result only. like Array ( [FIELD_1] => A [FIELD_2] => B [FIELD_3] => C [FIELD_4]=> D )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:08:27+00:00Added an answer on June 18, 2026 at 4:08 am

    Just use the following:

     $_MYSQL_DATA = array(); // you should declare your variables, even if it's not mandatory
     while($row = mysql_fetch_assoc($qry)) // USE PDO or MySQLi !!!!!
     {
        $_MYSQL_DATA[] = $row;
     }
    

    Note

    The [] operator generates the smallest, positive, numeric key that is not used in your array.

    Examples:

    $array = array(0 => 'b', 1 => 'a');
    $array[] = 'c'; // will place it in $array[2]
    
    $array = array();
    $array[] = 'a'; // will place in $array[0]
    

    And now … the rant about PDO / MySQLi (because I have to say it :P).

    MySQL is officially deprecated since PHP 5.5, and it will no longer be maintained. You should consider porting your code to either MySQLi or PDO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to store a json encoded array into a MySQL field. The
i m trying to convert php mysql_fetch_row result into javascript array so i write
I am trying to store sub-query result in session variable using MySQL, but the
I am trying to store URL Image paths into MySQL DB. But i am
I am trying to store and retrieve photos from a MySql database. Can someone
I'm trying to store an image into an SQL database without using temporary files.
i am trying to store devnagri (hindi) font in mysql but after the mysql
I'm working with Pig and I'm trying to store my results in a MySQL
I have a list of values I am trying to enter into a mysql
I am trying to use the result of a stored function in a WHERE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.