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

  • Home
  • SEARCH
  • 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 8277755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:46:51+00:00 2026-06-08T08:46:51+00:00

I’m newish to PHP and OOP and I have been using the PDO class

  • 0

I’m newish to PHP and OOP and I have been using the PDO class to connect and retrive info from my MYSQL database. Below is and excerpt of the files in question:

lyrics.class.php

<?php 
class lyrics{

public $con;
public $kill;
public function __construct(connection $con){

    $this->con = $con->con;     
}

public function getLyricsFromURL($lyricsid){
    $results;

    $getlyrics = $this->con->prepare("SELECT * FROM `lyrics` WHERE lyrics_id = :lyricsid");
    $getlyrics->bindParam(':lyricsid',$lyricsid,PDO::PARAM_INT);
    $getlyrics->execute();
    $results = $getlyrics->fetchAll(PDO::FETCH_OBJ);


    foreach ($results as $result) {

        echo $result->lyrics_content;


    }

}

index.php:

<?php
include 'inc/header.php';
include 'libs/connection.class.php';
include 'libs/lyrics.class.php';

$conn = new connection();
$lyrics = new lyrics($conn);

$lyrics->getLyricsFromURL(55);


?>

<h1><?php echo $lyrics->result->lyrics_title;?></h1>

OTHERS:
there is a connection class in another file but i won’t show it here, just know that the connection works.

The problem:*
The problem I’m having is i want to echo out individual column of results from the **getLyricsFromURL()
method in the lyrics class, I have tried but it doesn’t work.

What is the correct way to do this?

Thanks in advance.

  • 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-08T08:46:53+00:00Added an answer on June 8, 2026 at 8:46 am

    The method getLyricsFromURL() is setup to return an array of elements, but you are referencing the return value as a single element, try this:

    public function getLyricsFromURL($lyricsid){
    
        // This isn't necessary
        //$results;
    
         // Better to use $stmt as the variable here, obviously this is subjective
         // but will serve you better when you are working on other stmt objects
         $stmt = $this->con->prepare("SELECT * FROM `lyrics` WHERE lyrics_id = :lyricsid");
    
         $stmt->bindParam(':lyricsid', $lyricsid,PDO::PARAM_INT);
         $stmt->execute();
    
         $results = $stmt->fetchAll(PDO::FETCH_OBJ);
    
         return $results;
    }
    
    ...
    
    // Instatiate our lyrics object
    $lyric = new lyrics($conn);
    
    // Make request for lyrics associated to row #55 and store results in local var
    $lyrics = $lyric->getLyricsFromURL(55);
    
    // Notice we are referencing the first element of the array
    <h1><?php echo $lyrics[0]->lyrics_title;?></h1>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.