Mysql does not support object-oriented style, and in your script there are at least two references to class methods.
In this paragraph, in addition to the reference in the oriented style, the 0
is passed as string before a quantitative comparison operator. The example will work, but it is always better to treat an integer as an integer.
Of:
$exibe-> num_rows > '0'
To:
mysql_num_rows($exibe) > 0
Here was the same thing, reference to methods of a class that does not even exist.
Of:
$row = $exibe->fetch_assoc()
To:
$row = mysql_fetch_assoc($exibe)
The functions generate errors, for methods called from variables that are not objects. In this case, returned a E_NOTICE
Notice: Trying to get Property of non-object "localfile" online 9
Let’s also assume, that in your config.php` file are the connection variables, and also where you select the database, since you are using Mysql.
...
$emite = "SELECT ID, login FROM usuarios";
$exibe = mysql_query($emite);
if (mysql_num_rows($exibe) > 0) {
while($row = mysql_fetch_assoc($exibe)) {
echo "<br> id: ". $row["ID"]. " - login: ". $row["login"]. "<br>";
}
} else {
echo "0 resultados";
}
Another thing, is that the functions Mysql are obsolete, thus giving rise to the new and safer functions of the Mysqli which is a version of the old Mysql, but safer, or you can also use the PDO.
You can also see in this example, how your script would look, with the Mysqli:
$conexao = mysqli_connect("localhost", "usuario", "senha", "banco_de_dados");
$emite = "SELECT ID, login FROM usuarios";
$exibe = mysqli_query($conexao, $emite);
if (mysqli_num_rows($exibe) > 0) {
while($row = mysqli_fetch_assoc($exibe)) {
echo "<br> id: ". $row["id"]. " - login: ". $row["login"]. "<br>";
}
} else {
echo "0 resultados";
}
Some References:
There are also many good answers about Mysqli and the PDO here in the Sopt, just search them using the search bar on website.
recommended reading: http://answall.com/a/4675/13561
– Pedro Sanção
what is
localarquivo
and which is line 9?– Jorge B.
"Localfile" is the directory in which my system is located, I chose not to show it. @Jorgeb.
– Jorge Felix
Line 9 is line
while($row = $exibe->fetch_assoc()) {
– Jorge Felix
Turns out you’re mixing mysql_ and mysqli_. Only with the new version of
mysqli_
is that you can use as an object$exibe->fetch_assoc()
. Withmysql_
you can only usemysql_fetch_assoc($exibe)
. I advise you to change everything tomysqli_
, for more information read the link of Sanction.– Jorge B.
If you change from mysql (in depreciation) to mysqli, consider taking a look at PDO (http://php.net/manual/en/class.pdo.php)
– Thyago ThySofT