Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 5, 2019 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/1656285c81e8fda30ab1984782e4b8e1 to your computer and use it in GitHub Desktop.
Save parzibyte/1656285c81e8fda30ab1984782e4b8e1 to your computer and use it in GitHub Desktop.
<?php
/*
CRUD con SQL Server y PHP
@author parzibyte [parzibyte.me/blog]
@date 2019-06-03
================================
Este archivo lista todos los
datos de la tabla, pero en un
ciclo usando un cursor, no
a través de un arreglo
(se supone que es más eficiente)
================================
*/
?>
<?php
include_once "base_de_datos.php";
$consulta = "select id, nombre, edad from mascotas";
# Preparar sentencia e indicar que vamos a usar un cursor
$sentencia = $base_de_datos->prepare($consulta, [
PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL,
]);
# Ejecutar sin parámetros
$sentencia->execute();
# Forma de iterar
while ($mascota = $sentencia->fetchObject()){
# Aquí hacer algo con $mascota
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment