I see two problems, the first that you are overwriting the results and in the variable $json
you will always have the last record.
try putting this:
$json['peliculas'][] = $registro;
Another problem is that you are using mysqli_fetch_array
to recover the result without indicating the way you want the result, so for each record you return an associative and numeric array at the same time duplicating the records. This can cause problems when converting it to json
.
Try changing the line like this:
while ($registro = mysqli_fetch_assoc($resultado))
Here I leave your modified code:
<?php
include('conexion.php');
$json = array();
$link = conectarse();
$select = "SELECT * FROM peliculas";
$resultado = mysqli_query($link,$select);
while ($registro = mysqli_fetch_assoc($resultado)) {
$json['peliculas'][] = $registro;
}
mysqli_close($link);
echo json_encode($json, JSON_UNESCAPED_UNICODE);
?>
Here more information on mysqli_fetch_assoc and mysqli_fetch_array
EDITED BY COMMENT
To debug possible errors in the formation of json
the function json_last_error_msg is very useful () using it in the following way:
echo json_last_error_msg();
For example, it is common to get the following error:
Badly formed UTF-8 characters, possibly coded in a way
incorrect
This would be solvable by defining the charset of the database in your code as follows:
mysqli_set_charset($link, 'utf8');