views:

20

answers:

3

Hello all i try to select stuff from the database and when i will return it so i can echo stuff out like

$instance->titel $instance->content

and like that, hope you understand, now i only got the id "1" echo out.

here is my code

   <?php

/**
* Simon testClass
*/
class testClass
{
    public $mysqli;

    public function __construct()
    {
        $this->mysqli = new mysqli("localhost", "root", "root", "oop") or die("Der skete en fejl med database connection");

        if(mysqli_connect_errno())
        {
            echo "Der skete en fejl med database connection: " . mysqli_connect_errno();
        }#Lukker if mysqli database error
    }#Lukker __construct

    public function select($fields, $from)
    {
        $stmt = $this->mysqli->prepare("SELECT $fields FROM $from") or die($mysqli->error);
        #$stmt->bind_param('is', $id, $titel);
        #bind_result($fields);
        $stmt->execute();

        $object = $stmt->fetch();

        return $object;
    }#Lukker if prepare statment

    public function __destruct(){
        $this->mysqli->close();
    }
}#Lukker testClass
A: 

$stmt->fetch() doesn't actually return anything. It's intended to load a result row into bound variables, which you've commented out, so your $object won't contain the data being fetched. Docs on the function/method are here: http://php.net/mysqli_fetch

Note that it's deprecated.

Marc B
but this i have now
Simon
argh sorry i try againThis i have now$object = $stmt->fetch(); return $object;
Simon
how can i do so i can return all the info from the database?
Simon
try `$row = $stmt->fetch_assoc(); return $row`
Marc B
A: 

it still dont work :(, i have try this

$object = $stmt->fetch_object(); return $object;

so i can echo

$instance->titel $instance->content

and like that, but i cant get it to work

simon
A: 

i still need help, bump :/

simon