I was coding, while watching a Tutorial and i tried to figure why was this guy using while($row = $result->fetch_array())
but i was always using while($row = mysqli_fetch_array($result))
and i want to know if it matter or which way was right or wrong way?
Asked
Active
Viewed 66 times
0
-
You really shouldn't be using either one unless you know absolutely sure that `mysqlnd` will exist on the server your code will be run from. As using either requires a `mysqli_result` object. Which comes from `mysqli_query` (which you should not use), or a prepared statement and using `mysqli_stmt_get_result` (requires mysqlnd). – IncredibleHat Aug 02 '20 at 01:51
-
I don't know but I'v seen this and didn't understand – Aug 02 '20 at 02:19
-
Don't use either one. Use foreach loop instead – Dharman Aug 03 '20 at 09:40
1 Answers
-1
Actually $result->fetch_array())
and mysqli_fetch_array($result))
both do the same thing. But using $result->fetch_array())
is object oriented style and mysqli_fetch_array($result))
is traditional procedural style.
Also mysqli_fetch_array()
will collect the data from database as an array.
You can use any one of them. But I prefer object oriented style.

user3783243
- 5,368
- 5
- 22
- 41

Muhammad
- 52
- 7