Click here to Skip to main content
15,887,083 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: Help me in configuring the PHP .How to run a PHP program Pin
VickyVicki12-Dec-11 5:28
VickyVicki12-Dec-11 5:28 
QuestionAMPPS Perl Pin
Paul15866-Dec-11 2:06
Paul15866-Dec-11 2:06 
AnswerRe: AMPPS Perl Pin
Albert Holguin7-Dec-11 7:42
professionalAlbert Holguin7-Dec-11 7:42 
GeneralRe: AMPPS Perl Pin
jschell30-Dec-11 8:55
jschell30-Dec-11 8:55 
GeneralRe: AMPPS Perl Pin
Albert Holguin3-Jan-12 18:19
professionalAlbert Holguin3-Jan-12 18:19 
AnswerRe: AMPPS Perl Pin
jschell30-Dec-11 8:57
jschell30-Dec-11 8:57 
GeneralRe: AMPPS Perl Pin
Phil Hartfield10-Jan-12 8:25
Phil Hartfield10-Jan-12 8:25 
QuestionReturn list of object from a Class Pin
awedaonline5-Dec-11 22:36
awedaonline5-Dec-11 22:36 
Hi all,

I am new to PHP development after a reasonable experience with the .NET.

I have just created a class to return list of categories from the category table and display on my home page.

Below is my code snippets:

PHP
<?php

class Connection {
    
    private $username = "root";
    private $password = "password";
    private $dbName = "aweklin";
    private $host = "localhost";
    
    private $link;
    
    public function __construct() {
        $this->link = mysqli_connect($this->host, $this->username, $this->password);        
        if (!$this->link) {
            // todo: display error
        }
        if (!mysqli_set_charset($this->link, 'utf8')) {
            // todo: display error
        }
        if (!mysqli_select_db($this->link, $this->dbName)) {
            // todo: display error
        }
    }

    public function getAllCategories() {
        $sql = mysqli_query($this->link, "CALL getCategories()");
        while ($row = mysqli_fetch_array($sql)){
            $row['description'] . '<br />';
        }
        return $row;
    }
    public function executeQuery ($query) {
        if (!$this->query($query)) {
            // todo: display error
        }
    }
}

?>



on my home.php page, I have:

PHP
<?php include_once $_SERVER['DOCUMENT_ROOT'] . 'aweklin/classes/LinkHelper.php'; ?>
<?php include_once $_SERVER['DOCUMENT_ROOT'] . 'aweklin/classes/DB/Connection.php'; ?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="styles/layout.css" type="text/css" />
        <script type="text/javascript" src="script/ref/jquery-1.6.2.min.js" /></script>
    <title><?php StringHelper::getHtml($title, TRUE); ?></title>
    </head>
    <body>
        <div id="wraper">
            <?php
                LinkHelper::setPageHeader();
            ?>
            
            <div id="page">
                <article>
                    <div class="content">
                        <div class="title"><?php StringHelper::getHtml($title, TRUE); ?></div>
                        <?php 
//                            $link =mysqli_connect("localhost", "root", "password");        
//                            if (!$link) {
//                                echo 'Unable to connect to the database server';
//                            }
//                            if (!mysqli_set_charset($link, 'utf8')) {
//                                echo 'Unable to set character set';
//                            }
//                            if (!mysqli_select_db($link, 'aweklin')) {
//                                echo 'Unable to connect to the database aweklin';
//                            }
//                            $sql = mysqli_query($link, "CALL getCategories()");
//                            while ($row = mysqli_fetch_array($sql)){
//                                echo $row['description'] . '<br />';
//                            }
                        
                            $con = new Connection();
                            $cat[] = $con->getAllCategories();
                            foreach ($cat as $c) {
                                echo $c;
                            }
                        ?>
                    </div>
                </article>
            
                <?php
                    LinkHelper::setSideBar();
                ?>                
            </div>
            <?php
                LinkHelper::setPageFooter();
            ?>
        </div>
    </body>
</html>


The problem is, I got nothing displayed on the home.php page.
If you can notice, I comment out some block of code their, that worked for me. But I want to use OOP approach to do this.

Tell me, what am I getting wrong here?

Thanks.
AnswerRe: Return list of object from a Class Pin
Graham Breach5-Dec-11 23:54
Graham Breach5-Dec-11 23:54 
GeneralRe: Return list of object from a Class Pin
awedaonline6-Dec-11 0:22
awedaonline6-Dec-11 0:22 
GeneralRe: Return list of object from a Class Pin
Graham Breach6-Dec-11 0:52
Graham Breach6-Dec-11 0:52 
GeneralRe: Return list of object from a Class Pin
awedaonline6-Dec-11 1:01
awedaonline6-Dec-11 1:01 
QuestionInstalling GD2 with PHP on linux Pin
jiksaw2135-Dec-11 14:41
jiksaw2135-Dec-11 14:41 
QuestionMulti lingual Wordpress site Pin
CodingLover1-Dec-11 1:07
CodingLover1-Dec-11 1:07 
AnswerRe: Multi lingual Wordpress site Pin
Mohibur Rashid1-Dec-11 19:09
professionalMohibur Rashid1-Dec-11 19:09 
GeneralRe: Multi lingual Wordpress site Pin
CodingLover5-Dec-11 19:26
CodingLover5-Dec-11 19:26 
GeneralRe: Multi lingual Wordpress site Pin
Peter_in_27805-Dec-11 19:58
professionalPeter_in_27805-Dec-11 19:58 
GeneralRe: Multi lingual Wordpress site Pin
Mohibur Rashid5-Dec-11 20:20
professionalMohibur Rashid5-Dec-11 20:20 
QuestionPHP Form is not working. Pin
mkukulka30-Nov-11 21:23
mkukulka30-Nov-11 21:23 
AnswerRe: PHP Form is not working. Pin
Gerben Jongerius30-Nov-11 22:03
Gerben Jongerius30-Nov-11 22:03 
GeneralRe: PHP Form is not working. Pin
m_kukulka5-Dec-11 8:05
m_kukulka5-Dec-11 8:05 
AnswerRe: PHP Form is not working. Pin
kannan pichumani8-Dec-11 1:31
kannan pichumani8-Dec-11 1:31 
QuestionFrom name & email Pin
Jassim Rahma28-Nov-11 4:42
Jassim Rahma28-Nov-11 4:42 
AnswerRe: From name & email Pin
Graham Breach28-Nov-11 7:40
Graham Breach28-Nov-11 7:40 
QuestionPROPERTIES file in PHP Pin
Aniket S Kulkarni28-Nov-11 2:35
Aniket S Kulkarni28-Nov-11 2:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.