Skip to main content
Participant
June 8, 2012
Question

mysql functions

  • June 8, 2012
  • 1 reply
  • 1457 views

I have two questions

1)
after using the mysql_query() function you can read the returned data with mysql_result(), mysql_fetch_assoc() or mysql_fetch_array

1a)

I have always used the mysql_result() function myself would I be correct to think that the difference between this and the other two is that the other two do not need to be put into a loop in order to go through the rows of data one at a time?

1b)
What is the difference between mysql_fetch_assoc() and mysql_fetch_array?

2)

The PHP manual says that use of mysql_result(), mysql_fetch_assoc() or mysql_fetch_array is discouraged and that you should use the MySQLi or PDO_MySQL extensions instead

why is this?

This topic has been closed for replies.

1 reply

Rob Hecker2
Legend
June 10, 2012

1a) If the query returns more than one rown then of course you have to loop through them, but not if only one row is returned. Actually I find it odd that you have always used musql_result, which is the most retrictive method. I generally use fetch_assoc.

1b) fetch_assoc returns an associative array, fetch_array returns an indexed array, and mysql_result returns just one cell from a result set.

2) The mysql extension is old. The newer extensions provide much better security and more features. I like the way things are done with PDO; it takes an object oriented approach, but MySQLi is easier to switch to from the original extension. The two extensions offer very similar capabilities. Switch to one or the other as soon as you can.

Participant
June 16, 2012

I have started looking at the methods which mysqli provides
i have noticed that it has mysqli_result
is this very different from the old mysql_result method