Please help me with this simple SQL code

Links for php scripts

Moderators: gesf, Michalio

Post Reply
BBML

Hi!

I need to get all the data out from the database. Maybe I have to get the data into a variable and then I can do stuff with it? (I'm doing stuff with the data in C#)

<?php

$con = mysqli_connect('topsecret');

if (mysqli_connect_errno())
{
echo "connection failed";
exit();
}

$sql = "SELECT * FROM data;";
mysqli_query($con, $sql) or die("Failed to get data");

echo "OK";

?>
User avatar
Michalio
Moderator
Moderator
Posts: 339
Joined: Sun Jul 18, 2021 1:33 pm
Location: Poland

The "data" is a reserved mysql keyword (https://dev.mysql.com/doc/refman/8.0/en/keywords.html).
To be sure the query is valid use this syntax:

Code: Select all

SELECT * FROM `data`
Free coding lessons: https://php-forum.com/phpforum/viewtopic.php?t=29852
Post Reply