MySQL, how to use returned data?

Well, I know that there is funciton mysql_fetch_array (), and we can use it as follows:

while ($row = mysql_fetch_array($result)) { echo $row['name'] . "<br />"; } 

But is there any other way? For example, if there is only one element that can be returned, not an array.

Thanks)

+4
source share
4 answers

If there is only one line, you can simply say:

 $row = mysql_fetch_array($result); 

Or you can use mysql_fetch_row if you want.

But I would repeat Eric's comment to go with PDO . Here's a good tutorial that makes heavy use of PDO .

+1
source

see mysql_result () :

Retrieves the contents of a single cell from the MySQL result set.
+4
source

You can use mysql_result

 $result = mysql_query($query) or die(mysql_error()); $scalar = mysql_result($result, 0); 
+1
source

For example, if there is only one element that can be returned, not an array.

Nope.
Only an array or useless object you can get.

-1
source

Source: https://habr.com/ru/post/1311185/


All Articles