0

*Following up from a previous post Server connection failed

 <?php

$servername = "localhost:3306";
$username = "brazen_test_gallary";
$password = "1234";
$dbname = "brazen_galleryexample";


$conn = mysqli_connect($servername, $username, $password, $dbname);

On my previous post, I was advised to remove the port number "3306" from the server name but that resulted in the following error :

Fatal error : Uncaught Error: Call to undefined function mysqli_stmt_get_result()

The lines that the error directed me to are written below:

<?php
        include_once 'includes/dbh.inc.php';

        $sql = "SELECT * FROM gallery ORDER BY orderGallery DESC;";

        $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
          echo "SQL statement failed!";
        } else {
          mysqli_stmt_execute($stmt);
          $result = mysqli_stmt_get_result($stmt);

          while ($row = mysqli_fetch_assoc($result)) {
            echo '<a href="#">
              <div style="background-image: 
url(img/gallery/'.$row["imgFullNameGallery"].');"></div>
              <h3>'.$row["titleGallery"].'</h3>
              <p>'.$row["descGallery"].'</p>
            </a>';
          }
        }
        ?>

I looked at similar errors on StackOverflow, some of them said to update the PHP version on Cpanel. I tried that but no change. I want to establish a connection with my server in Hostgator but this error is not letting that happen.

brazencore
  • 17
  • 7
  • You have `global $con;` and `$conn`. One of those is wrong. What is the connection's variable that is used? – Funk Forty Niner Jan 07 '20 at 21:12
  • What you posted doesn't qualify as a prepared statement. You have not passed anything in the query for it. Just `query()` in this case will suffice. – Funk Forty Niner Jan 07 '20 at 21:13
  • sorry, the " global $con" is by. I was trying a method described in another question asked on this site. – brazencore Jan 07 '20 at 21:16
  • You didn't even mention which PHP version you use. Did you enable the nd_mysqli driver? – Dharman Jan 07 '20 at 22:02
  • I am using version 7.1. I am trying to enable the nd_mysqli driver rn but still couldn't do it. Looking at other posts to get an understanding of what to do. – brazencore Jan 07 '20 at 23:20

0 Answers0