ERRO EM PHP

18/09/2019

0

Alguém pode me ajudar????

public function logar() {
$pdo = parent::getConn();

$logar = $pdo->prepare("SELECT * FROM usuarios WHERE email = ? AND senha = ?");
$logar->bindValue(1, $this->getLogin());
$logar->bindValue(2, $this->getSenha());
$logar->execute();
if ($logar->rowCount() == 1):

está dando erro na linha "$logar->execute();"

: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in C:\xampp\htdocs\rede-social-em-php-master\rede-social-em-php-master\panel\app\database\Validation.class.php:30 Stack trace: #0 C:\xampp\htdocs\rede-social-em-php-master\rede-social-em-php-master\panel\app\database\Validation.class.php(30): PDOStatement->execute() #1 C:\xampp\htdocs\rede-social-em-php-master\rede-social-em-php-master\panel\resource\views\site\header.php(27): Validation->logar() #2 C:\xampp\htdocs\rede-social-em-php-master\rede-social-em-php-master\index.php(24): include_once(''''C:\\xampp\\htdocs...'''') #3 thrown in
C:\xampp\htdocs\rede-social-em-php-master\rede-social-em-php-master\panel\app\database\Validation.class.php
on line
30
Pedro B

Pedro B

Responder

Posts

18/09/2019

Joao Nascimento

Onde está o código que faz a conexão com o servidor?
Responder

19/09/2019

Pedro B

Onde está o código que faz a conexão com o servidor?


CREATE TABLE IF NOT EXISTS `chat` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`de` int(11) DEFAULT 0,
`para` int(11) DEFAULT 0,
`msg` text COLLATE utf8_unicode_ci DEFAULT ''0'',
`status` enum(''V'',''NV'') COLLATE utf8_unicode_ci DEFAULT ''NV'',
`updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`created` timestamp NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `Index 2` (`de`),
KEY `Index 3` (`para`),
CONSTRAINT `FK_chat_usuarios` FOREIGN KEY (`de`) REFERENCES `usuarios` (`id`),
CONSTRAINT `FK_chat_usuarios_2` FOREIGN KEY (`para`) REFERENCES `usuarios` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Exportação de dados foi desmarcado.
-- Copiando estrutura para tabela redesocial.comentarios
CREATE TABLE IF NOT EXISTS `comentarios` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`comentario` text COLLATE utf8_unicode_ci DEFAULT NULL,
`id_post` int(11) DEFAULT NULL,
`id_usuario` int(11) DEFAULT NULL,
`data_created` timestamp NULL DEFAULT current_timestamp(),
`data_update` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `Index 2` (`id_post`),
KEY `Index 3` (`id_usuario`),
CONSTRAINT `FK_comentarios_posts` FOREIGN KEY (`id_post`) REFERENCES `posts` (`id`),
CONSTRAINT `FK_comentarios_usuarios` FOREIGN KEY (`id_usuario`) REFERENCES `usuarios` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=106 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Exportação de dados foi desmarcado.
-- Copiando estrutura para tabela redesocial.likes
CREATE TABLE IF NOT EXISTS `likes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_usuario` int(11) DEFAULT 0,
`curtiu` enum(''SIM'',''NAO'') COLLATE utf8_unicode_ci DEFAULT ''NAO'',
`id_post` int(11) DEFAULT 0,
`data_created` timestamp NULL DEFAULT current_timestamp(),
`data_update` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `unique_curtidas_post` (`id_usuario`,`id_post`),
KEY `Index 2` (`id_usuario`,`id_post`),
KEY `FK_curtidas_posts` (`id_post`),
CONSTRAINT `FK_curtidas_posts` FOREIGN KEY (`id_post`) REFERENCES `posts` (`id`),
CONSTRAINT `FK_curtidas_usuarios` FOREIGN KEY (`id_usuario`) REFERENCES `usuarios` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Exportação de dados foi desmarcado.
-- Copiando estrutura para tabela redesocial.posts
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`img` varchar(250) COLLATE utf8_unicode_ci DEFAULT ''0'',
`legenda` text COLLATE utf8_unicode_ci DEFAULT ''0'',
`id_usuario` int(11) DEFAULT 0,
`data_created` timestamp NULL DEFAULT current_timestamp(),
`data_update` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `Index 2` (`id_usuario`),
CONSTRAINT `FK__usuarios` FOREIGN KEY (`id_usuario`) REFERENCES `usuarios` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Exportação de dados foi desmarcado.
-- Copiando estrutura para tabela redesocial.seguidores
CREATE TABLE IF NOT EXISTS `seguidores` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_user` int(11) NOT NULL DEFAULT 0,
`id_seguindo` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Exportação de dados foi desmarcado.
-- Copiando estrutura para tabela redesocial.usuarios
CREATE TABLE IF NOT EXISTS `usuarios` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`avatar` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`telefone` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`senha` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`tipo` enum(''V'',''C'') COLLATE utf8_unicode_ci DEFAULT NULL,
`descricao` text COLLATE utf8_unicode_ci DEFAULT NULL,
`sexo` enum(''M'',''F'') COLLATE utf8_unicode_ci DEFAULT NULL,
`data_created` timestamp NULL DEFAULT current_timestamp(),
`data_update` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Exportação de dados foi desmarcado.
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '''') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
Responder

20/09/2019

Joao Nascimento

Não não, estou me referindo ao código que faz a conexão ao servidor do banco de dados com usuário senha ...
Esse código é para criar a estrutura do banco
Responder

22/09/2019

Pedro B

Não não, estou me referindo ao código que faz a conexão ao servidor do banco de dados com usuário senha ...
Esse código é para criar a estrutura do banco


Ahh...
<?php

abstract class Conn {

private static $Host = HOST;
private static $User = USER;
private static $Pass = PASS;
private static $Bd = BD;
private static $Connect = null;

private static function Conectar() {
try {
if (self::$Connect == null):
self::$Connect = new PDO('mysql:host=' . self::$Host . ';dbname=' . self::$Bd, self::$User, self::$Pass);
endif;
} catch (PDOException $e) {
echo 'Message: ' . $e->getMessage();
die;
}
self::$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$Connect;
}

protected static function getConn() {
return self::Conectar();
}
Responder

Que tal ter acesso a um e-book gratuito que vai te ajudar muito nesse momento decisivo?

Ver ebook

Recomendado pra quem ainda não iniciou o estudos.

Eu quero
Ver ebook

Recomendado para quem está passando por dificuldades nessa etapa inicial

Eu quero

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar