11.09.2018 Views

Aprender a desarrollar un sitio Web con PHP y MySQL

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Crear <strong>un</strong> blog (objeto)<br />

Vuelva a repetir el ejercicio A, pero ahora utilice objetos.<br />

Cree <strong>un</strong>a clase Blog cuyos atributos coincidan <strong>con</strong> los campos de la tabla Contenido. Cree <strong>un</strong>a clase<br />

Manager que tenga la <strong>con</strong>exión PDO como atributo, así como <strong>un</strong>os métodos que permitan leer y escribir<br />

en la tabla Contenido. Las páginas mostrar_blog.php, insertar_<strong>con</strong>tenido.php y añadir_<strong>con</strong>tenido.php no<br />

deben <strong>con</strong>tener <strong>con</strong>sultas SQL.<br />

Solución<br />

Cree la base de datos Blog<br />

El script SQL que crea la tabla Contenido es:<br />

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";<br />

--<br />

-- Base de datos : `Blog`<br />

--<br />

-- --------------------------------------------------------<br />

--<br />

-- Estructura de la tabla `<strong>con</strong>tenido`<br />

--<br />

DROP TABLE IF EXISTS `<strong>con</strong>tenido`;<br />

CREATE TABLE IF NOT EXISTS `<strong>con</strong>tenido` (<br />

`Id` int(11) NOT NULL AUTO_INCREMENT,<br />

`Titulo` varchar(25) NOT NULL,<br />

`Fecha` Datetime NOT NULL,<br />

`Comentario` text NOT NULL,<br />

`Imagen` varchar(25) NOT NULL,<br />

PRIMARY KEY (`Id`)<br />

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;<br />

La página formulario_añadir.php es:<br />

<br />

<br />

<br />

Blog<br />

<br />

<br />

<br />

Formulario para añadir el <strong>con</strong>tenido al Blog<br />

<br />

Título: <br />

Comentario: <br />

<br />

Seleccione <strong>un</strong>a foto que tenga <strong>un</strong> tamaño inferior a 2 MB.<br />

<br />

<br />

www.FreeLibros.me

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!