0

I'm still learning and don't know which PHP\MySQL query is more proper? they both work fine but I'm using second one

$query = "SELECT Id, username, email FROM members";
$result = $conn->query($query);
  if ($result) {
   while ($row = mysqli_fetch_array($result)){

or

$query = mysqli_query($conn,"SELECT Id, username FROM members");

if ($query) {
while ($row = mysqli_fetch_array($query))
Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
Adnan
  • 101
  • 2
  • 10
  • possible duplicate of [Why is object oriented PHP with mysqli better than the procedural approach?](http://stackoverflow.com/questions/14710195/why-is-object-oriented-php-with-mysqli-better-than-the-procedural-approach) – A l w a y s S u n n y May 11 '15 at 15:49
  • They are both equally fine. Depends on wider context, which one would be more appropriate for the current situation. – mondjunge May 11 '15 at 15:50

1 Answers1

1

The answer is subjective (matter of opinion).

The first code snippet is Object Orientated, the second is Procedural. If I were you, I'd use whichever code style you use in the rest of your project, neither is "better", although some would probably argue that OO is better practice.

Jonathan Clark
  • 1,180
  • 1
  • 8
  • 26