Why can't I get data from mysql db table using mysqli_query?

I'm at the prototype stage, so I have it error_reporting(-1);

in my first line. Regardless, I have no php error but php prints was unable to get the data .

As I understood from php.net manual and similar stackoverflow cases my $ sorgula returns FALSE.

But why? You can help by counting

//i am sure that i am connected to db
if ($sorgula = mysqli_query($dbc, "SELECT * FROM tb_yazilar ORDER BY kolon_sn"))
{
    while ($satir = mysqli_fetch_array($sorgula, MYSQLI_ASSOC)) 
    {
    echo $satir['kolon_yazar'].' - '.$satir['kolon_baslik'].' - '.$satir['kolon_yazi'].' - '.$satir['kolon_etiketler'].' - '.$satir['kolon_ytarihi'].' -  -  -  - ';
    }
}
else 
{
echo 'could not get data';
}

mysqli_close($dbc);

      

+3


source to share


2 answers


try using mysqli_error

in your code.

procedural example:



$sorgula = mysqli_query($dbc, "SELECT * FROM tb_yazilar ORDER BY kolon_sn")
           or error_log(mysqli_error($dbc));

      

0


source


I used this and it worked: without the if, after retrieving it, go back and add the if. :)



require 'db.php';
$query = "SELECT * FROM thoughts";
$result = mysqli_query($conn, $query);
while($row=mysqli_fetch_assoc($result)) {
echo "<td>" . "TEXT: ". $row['text'] . "</td>";
}
mysqli_close($conn);

      

0


source







All Articles