// Variables $hostDB = '127.0.0.1'; $nombreDB = 'ejemplo'; $usuarioDB = 'root'; $contrasenyaDB = '123'; // Conecta con base de datos $hostPDO = "mysql:host=$hostDB;dbname=$nombreDB;"; $miPDO = new PDO($hostPDO, $usuarioDB, $contrasenyaDB); // Prepara SELECT $miConsulta = $miPDO->prepare('SELECT * FROM Escuelas;'); // Ejecuta consulta $miConsulta->execute(); // Imprimo $resultados = $miConsulta->fetchAll(); foreach ($resultados as $posicion => $columna) { echo $columna['nombre']; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter