Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Mam problem z fetchAll php wersja 7.4.9
Dr4GoN
post 18.09.2020, 12:47:28
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.09.2020

Ostrzeżenie: (0%)
-----


Wywala mi oto taki błąd:
Warning: PDOStatement::fetchAll() expects parameter 1 to be int, string given in C:\xampp\htdocs\testowa\rejestracja\registration.php on line 37

Czepia się tego:
$result = $statement->fetchAll('fetch_style: PDO::FETCH_ASSOC');


cała funkcja:
$statement = $connection->prepare('statement: SELECT * FROM user WHERE email = :email OR numer = :numer');
if($statement){
$result = $statement->execute([
':email' => $data['email'],
':numer' => $data['phone'],
]);

$result = $statement->fetchAll('fetch_style: PDO::FETCH_ASSOC');

if(!empty($result)){
$_SESSION['messages'] [] = 'Podany adres e-mail lub numer telefonu jest już przypisany do konta';
header('string: Location: register.php');
exit;
}


}


Czy ktoś wie jak mogę to naprawić?
Z góry dziękuję za pomoc biggrin.gif
Go to the top of the page
+Quote Post
viking
post 18.09.2020, 12:53:35
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


A co to niby za przedrostki fetch_style, statement? PDO::FETCH_ASSOC to stała a nie string
$result = $statement->fetchAll(\PDO::FETCH_ASSOC);


--------------------
Go to the top of the page
+Quote Post
Dr4GoN
post 18.09.2020, 12:58:56
Post #3





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.09.2020

Ostrzeżenie: (0%)
-----


Cytat(viking @ 18.09.2020, 13:53:35 ) *
A co to niby za przedrostki fetch_style, statement? PDO::FETCH_ASSOC to stała a nie string
$result = $statement->fetchAll(\PDO::FETCH_ASSOC);


Dopiero uczę się php i skorzystałem z tego poradnika:
https://magemastery.net/courses/user-regist...in-the-database

Dziękuję za pomoc biggrin.gif
Go to the top of the page
+Quote Post
trueblue
post 18.09.2020, 13:09:21
Post #4





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Jeśli używasz głównie FETCH_ASSOC, to możesz ustawić to sobie zaraz po połączeniu z bazą danych.
  1. $connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

Nie będziesz musiał wpisywać tego za każdym razem.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 17:40