Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Function to fetch all rows of dbquery()

Asked Modified Viewed 2,162 times
R
Routh
R
Routh 10
Chris Routh
Founder of The Den of Amateur Writing

"Don't try to be a great man; just be a man and let history make its own judgments." - Riker, Star Trek The Next Generation
  • Member, joined since
  • Contributed 67 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
asked
Member

dbarray() fetches one row into an associative array.

I need to fetch all rows into an array of associative arrays like mysqli_result::fetch_all or mysqli_fetch_all so I can do this:

$results[0]['title]

How do I do this in PHPFusion 9?
0 replies

6 posts

F
Falk
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
answered
Super Admin

Here is one example with two methods in 1. ( Not tested but you get the idea )

   $result = dbquery("SELECT * FROM ".DB_XXX."");
   $rows = dbrows($result);
         
   if ($rows != 0) {
      while ($data = dbarray($result)) {

      // if you need an extra passable array, build it in loop.
      $extra_array = array();
      $extra_array = $data['my_database_table']; // populate the workable array
      
      echo $data['my_database_table']; // or just use it on the fly
   
      }
      
   } else {
      echo "no results";
   }
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

Fetch all Rows, it's not in the native function yet.


$result = \PHPFusion\Database\DatabaseFactory::getConnection('default')->query($query, $param);
$rows = \PHPFusion\Database\DatabaseFactory::getConnection('default')->fetchAllRows($$result);
Edited by Chan on 09-06-2017 03:18,
0 replies
R
Routh
R
Routh 10
Chris Routh
Founder of The Den of Amateur Writing

"Don't try to be a great man; just be a man and let history make its own judgments." - Riker, Star Trek The Next Generation
  • Member, joined since
  • Contributed 67 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
answered
Member

Thank you both. Falk, your method was what I was trying to avoid. Chan's method is what I wanted, to avoid the overhead of a loop.

Would be nice to expose this as a native function.
0 replies
R
Routh
R
Routh 10
Chris Routh
Founder of The Den of Amateur Writing

"Don't try to be a great man; just be a man and let history make its own judgments." - Riker, Star Trek The Next Generation
  • Member, joined since
  • Contributed 67 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
answered
Member

@Chan

using your code, and passing a simple SQL query to it, results in the following error:

Fatal error: Call to a member function setFetchMode() on null in /var/www/html/includes/classes/PHPFusion/Database/Driver/PDOMySQL.php on line 174

I used this as a function from your code:

function fetchFullArray($query, $params=NULL) {
    $result = \PHPFusion\Database\DatabaseFactory::getConnection('default')->query($query, $params);
    $rows = \PHPFusion\Database\DatabaseFactory::getConnection('default')->fetchAllRows($result);
    return $rows;
}


Any idea why? I'm just doing a SELECT * FROM table LIMIT 25; as a test.


UPDATE: It works suddenly... Odd.
Edited by Routh on 10-06-2017 18:15,
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

Yes, we can certainly do that. Bring up an issue in Github please, so we won't miss it. I'm still busy doing invention now.
0 replies
F
Falk
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
answered
Super Admin

Easy today as well , just wrap it then

$data = dbarray(dbquery("SELECT * FROM ".DB_XXX.""));
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 6 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

F
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
R
R
Routh 10
Chris Routh
Founder of The Den of Amateur Writing

"Don't try to be a great man; just be a man and let history make its own judgments." - Riker, Star Trek The Next Generation
  • Member, joined since
  • Contributed 67 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet