title: How to fetch a single row from a MySQL DB using MySQLi with PHP?
body: <p>I am using PHP with MySQli and I want to fetch a single row from the whole SQL DB, which fits in my condition. Just for a note, this is what my current database looks like :</p>
  <p><a href="https://i.stack.imgur.com/Okwvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Okwvf.png" alt="sample database" /></a></p>
  <p>I want to get that single row where, eg. <code>txnid</code> column's value == <code>$txnid (a variable)</code>. I tried to build the SQL Query which would fit my requirements, and here's how it looks like : <strong><code>$sql = &quot;SELECT * FROM 'table1' WHERE 'txnid' = &quot; . $txnid;</code></strong>. When I raw-run this Query in phpMyAdmin, it works as expected. I just want to know, after I run the Query in PHP, how to fetch that row's data which came in as response from the Query using MySQLi?</p>
  <p>This is the code which I am using to run the Query :</p>
  <pre><code>$servername = &quot;localhost&quot;;
  $username = &quot;XXXXXXXXXXXXXX&quot;;
  $password = &quot;XXXXXXXXXXXXXX&quot;;
  $dbname = &quot;XXXXXXXXXXXXXXXX&quot;;
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  
  if ($conn-&gt;connect_error) {
    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);
  }
  
  $txnid = $_GET['id'];
  
  $sql = &quot;SELECT * FROM `testtable1` WHERE `txnid` = &quot; . $txnid;
  
  if ($conn-&gt;query($sql) === TRUE) {
      echo &quot;&quot;; //what should I do here, if I want to echo the 'date' param of the fetched row?
  } else {
      echo &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . $conn-&gt;error . &quot;&lt;br&gt;&quot;;
  }
  </code></pre>