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

Linux, Apache, MySQL, PHP

 
Questionerror in login page Pin
Jassim Rahma10-Dec-11 2:14
Jassim Rahma10-Dec-11 2:14 
AnswerRe: error in login page Pin
Graham Breach10-Dec-11 3:46
Graham Breach10-Dec-11 3:46 
GeneralRe: error in login page Pin
Jassim Rahma10-Dec-11 3:55
Jassim Rahma10-Dec-11 3:55 
GeneralRe: error in login page Pin
Graham Breach10-Dec-11 4:10
Graham Breach10-Dec-11 4:10 
Questionplz help - htaccess Pin
Jassim Rahma9-Dec-11 2:52
Jassim Rahma9-Dec-11 2:52 
QuestionSimple PHP Pin
omanzo_barrett8-Dec-11 8:39
omanzo_barrett8-Dec-11 8:39 
QuestionHelp me in configuring the PHP .How to run a PHP program Pin
VickyVicki8-Dec-11 4:32
VickyVicki8-Dec-11 4:32 
AnswerRe: Help me in configuring the PHP .How to run a PHP program Pin
awedaonline8-Dec-11 10:01
awedaonline8-Dec-11 10:01 
GeneralRe: Help me in configuring the PHP .How to run a PHP program Pin
VickyVicki9-Dec-11 4:38
VickyVicki9-Dec-11 4:38 
GeneralRe: Help me in configuring the PHP .How to run a PHP program Pin
awedaonline9-Dec-11 4:48
awedaonline9-Dec-11 4:48 
GeneralRe: Help me in configuring the PHP .How to run a PHP program Pin
VickyVicki9-Dec-11 5:55
VickyVicki9-Dec-11 5:55 
GeneralRe: Help me in configuring the PHP .How to run a PHP program Pin
awedaonline11-Dec-11 11:01
awedaonline11-Dec-11 11:01 
GeneralRe: Help me in configuring the PHP .How to run a PHP program Pin
Gerben Jongerius11-Dec-11 19:29
Gerben Jongerius11-Dec-11 19:29 
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 

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.