0

Does anyone sees any fault?

<?php 
             $sql = 'SELECT * FROM messages';
$result = $database->sql_query($sql);

while ($row = $database->sql_fetchrow($result))
{
   echo $row['message'];
}
                ?>

and my database connection

$database = mysql_select_db(DB_DATABASE) or die(mysql_error());

4
Contributors
4
Replies
30
Views
3 Years
Discussion Span
Last Post by SimonIoa
0

$database = mysql_select_db(DB_DATABASE)

That returns a resource.

$database->sql_query($sql);

This implies an object.

Where did you get that code? I think you are mixing up different solutions. Check the PHP code snippets, there are samples for MySQL, MySQLi and PDO.

0

I believe that it should look something like this:

$my_conn = new mysqli('localhost', 'user name', 'password', 'database name');
$sql = "SELECT * FROM messages";
$result = $my_conn->query($sql);
while ($obj = $result->fetch_object()) {
    echo = $obj->message;
}

I could easily be wrong though ...

hope this helps,

Simon.

Edited by slyme: typo

0

use this piece of code and replace dbname with your database name

<?php
mysql_connect("localhost","root","");
mysql_select_db("dbname");
$qry = mysql_query("SELECT * FROM messages");
while ($row = mysql_fetch_array($qry))
{
   echo $row['message'];?><br /><?php
}
?>

hope this helps you.

Edited by pritaeas: Removed fake signature.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.