I am quite new in PHP and Mysql and keep getting this error
<?php
$mysqli = new mysqli("localhost", "root", "root");
$mysqli->select_db("maturita");
$sql=$mysqli->query("SELECT name,description FROM `gallery`");
echo $sql;
?>
mysqli->query returns a mysqli_result object, not a string (the error is pretty descriptive).
To query the results, use the fetch functions.
ex:
while ( $rows = $resource->fetch_assoc() ) {
echo $rows['field'];
}
(beign $resource the result of your query)
The manual says (https://secure.php.net/manual/en/mysqli.query.php):
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
So the error is because the PHP can not convert the mysqli_result object to string in the echo function.
You can change you code to:
<?php
$mysqli = new mysqli("localhost", "root", "root");
$mysqli->select_db("maturita");
$sql=$mysqli->query("SELECT name,description FROM `gallery`");
print_r($sql->fetch_all());
?>
The result will be the array structure of the result.
The description of mysqli_result and other function can be found here: https://secure.php.net/manual/en/class.mysqli-result.php