Obsolete Mysql: Do not use mysql functions_*
The Mysql library, which has functions such as mysql_connect, mysql_query and the like, does not allow you to use new Mysql features such as triggers, stored procedures and others. These features are only available with the use of the Mysqli library.
The Mysqli extension has existed since PHP 5.0, which was released on July 13, 2004. Since then, it has been recommended to use Mysqli instead of Mysql.
However, many programmers continued to use (and still use) the Mysql library.
To change this scenario, the PHP team took a somewhat drastic attitude: it removed the Mysql library from PHP 7.
Alternatives to the Mysql extension
- Use the Mysqli extension instead of Mysql.
- Use PDO extension (PHP Data Object).
Example using PDO
works in any version of Mysql - test here
/******************** conexão *********************************************
$hostname="localhost";
$username="USUARIO";
$password="SENHA";
$db = "Nome_BD";
$pdo = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
**************************************************************************/
$sql= "SELECT login, pontos FROM usuarios order by pontos DESC limit 1";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$obj = $stmt->fetchObject();
echo $obj->login;
echo $obj->pontos;
Have you tried selecting the first record by ordering them down? Something like
SELECT ... FROM usuarios ORDER BY pontos DESC LIMIT 1
.– Woss
It is because it would not be on the same partition. It would have its own partition, for example: HIGHER SCORER: .. Hence the information, you know?
– Thiago Vinícius
No. What is the relation of this "partition" with SQL?
– Woss
Partition I referred to HTML "div", sorry for irreverence...
– Thiago Vinícius
Have you tried:
SELECT login, MAX(pontos) FROM usuarios
– Sam
Sam, I’m pretty layabout in PHP myself. How would you do that, please?
– Thiago Vinícius
What if there is more than one user with the same maximum score? Should all of them be returned? If not, what should be the criterion to define which will be returned?
– Woss
Next, with version 8 I tested so
SELECT nome, MAX(pontos) as maior FROM usuarios group by id limit 1
and it worked fine! https://www.db-fiddle.com/f/ch7WYBguAY3jo9QMZnpLpL/0– user60252
@Leocaracciolo Deu certinho by coincidence. Change the value of Beltrano to 198 and rotate, will return the Fulano again.
– Sam
No, I don’t know why the cancellation.
– Thiago Vinícius
is that you can only mark 1 response. If you mark the other one, the one that was marked earlier is unchecked.
– Sam