Simples

<< Click to Display Table of Contents >>

Navigation:  PDO >

Simples

Previous pageReturn to chapter overviewNext page

database aula : mysql

 

CREATE TABLE `tb_cliente` (

`id` INT(11) NOT NULL AUTO_INCREMENT,

`nome` VARCHAR(50) NOT NULL DEFAULT '',

`nasc` DATE NOT NULL,

`limite` DECIMAL(10,2) NOT NULL DEFAULT '0.00',

PRIMARY KEY (`id`)

)

COLLATE='utf8_general_ci'

ENGINE=InnoDB;

 

Principal.php

 

try {
    $pdo = new PDO("mysql:host=localhost;dbname=aula",
            "root",
            "123456",
            [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]);
 
    $qy = $pdo->query("select * from tb_cliente order by nome");
    while ($linha = $qy->fetch(PDO::FETCH_ASSOC)) {
        echo "<p>" . $linha["nome"] . "</p>";
    }
catch (PDOException $ex) {
    echo "<p>{$ex->getMessage()}</p>";
finally {
    echo "<p>FIM</p>";
}

 

Saída

 

Cris

 

Junior

 

FIM