Help with PHP - MYSQL

Status
This thread has been locked.
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Arrron

Freelance Web Developer
Supreme
Feedback score
3
Posts
46
Reactions
16
Resources
0
Pebbbles

Depends on whether you're using MySQL or MySQLi (I suggest MySQLi). Here's options for both.

For MySQL:
PHP:
<?php

    $query = mysql_query("SELECT * FROM table");
    $numberOfRows = mysql_num_rows($query);

    echo "The number of rows is: " . $numberOfRows;

?>

For MySQLi:
PHP:
<?php

    $connection = mysqli_connect("localhost","username","password","db_name");

    $query = mysqli_query($connection, "SELECT * FROM table");
    $numberOfRows = mysqli_num_rows($query);

    echo "The number of rows is: " . $numberOfRows;

?>
 
Last edited:

Jack

Retired Moderator
Supreme
Feedback score
11
Posts
1,210
Reactions
1,462
Resources
0
Pebbbles

Depends on whether you're using MySQL or MySQLi (I suggest MySQLi). Here's options for both.

For MySQL:
PHP:
<?php

    $query = mysql_query("SELECT * FROM table");
    $numberOfRows = mysql_num_rows($query);

    echo "The number of rows is: " . $numberOfRows;

?>

For MySQLi:
PHP:
<?php

    $connection = mysqli_connect("localhost","username","password","db_name");

    $query = mysqli_query($connection, "SELECT * FROM table");
    $numberOfRows = mysqli_num_rows($query);

    echo "The number of rows is: " . $numberOfRows;

?>
The original MySQL API (mysql) was deprecated in PHP 5.5 and removed in PHP 7.0. Current stable PHP is 7.3.
So you will definitely need to use the improved MySQL API (mysqli).
 
Status
This thread has been locked.
Top