Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Error HY093
matjajko
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


Witam, otóż borykam się z pewnym problemem i nie wiem co jest nie tak... Dajmy na to parametry funkcji to $table = 'users', $col = 'name' i $value = 'test'. Problem w tym, że wyskakuje komunikat:

Kod
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in XXXX on line XX
PDO::errorCode(): HY093


Kod
function addTo($table,$col,$value)
    {
        
        
        
        
        if($query = $this->connection->prepare("INSERT INTO :table (:col)
        VALUES (':value')")){
                
            echo gettype($table);
            echo gettype($col);
            echo gettype($value);
            $query->bindParam(':table',$table);
            $query->bindParam(':col',$col);
            $query->bindParam(':value',$value);
            $query->execute();
            echo "\nPDO::errorCode(): ", $query->errorCode();
        }
        
    }


Co może być nie tak?
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Nazwy tabeli nie binduje się, a bindowanego parametru nie obejmuje się cudzysłowami.
Go to the top of the page
+Quote Post
matjajko
post
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


Po zmianie pojawia się error 42000
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Po jakiej zmianie?
Go to the top of the page
+Quote Post
matjajko
post
Post #5





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


Kod
function addTo($col,$value)
    {
        
        
        
        
        if($query = $this->connection->prepare("INSERT INTO users (:col)
VALUES (':value')")){
                


            echo gettype($row);
            echo gettype($value);

            $query->bindValue(':col',$col);
            $query->bindValue(':value',$value);
            $query->execute();
            echo "\nPDO::errorCode(): ", $query->errorCode();
        }
        
    }
Go to the top of the page
+Quote Post
trueblue
post
Post #6





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Dopiero połowa poprawek.
Go to the top of the page
+Quote Post
matjajko
post
Post #7





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


Przecież objąłem w apostrofy, a nie cudzysłowy. Sam już się pogubiłem co źle zrobiłem.
Go to the top of the page
+Quote Post
trueblue
post
Post #8





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Pojedynczy cudzysłów = apostrof.

  1. VALUES (':value')

Go to the top of the page
+Quote Post
matjajko
post
Post #9





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


Po usunięciu '' ciągle jest error 42000.
Go to the top of the page
+Quote Post
trueblue
post
Post #10





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Bindujesz $row czy $col?
Go to the top of the page
+Quote Post
matjajko
post
Post #11





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


No $col, $row to było stare, zapomnialem tutaj usunąć sprawdzenia typu (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post
trueblue
post
Post #12





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Pokaż co masz w $col i $value.
Go to the top of the page
+Quote Post
matjajko
post
Post #13





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 29.06.2018

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


Funkcje wywołuje, z parametrami: AddTo("name","test") czyli chce do kolumny name dodać "test". Obydwa stringi i poprawność jest dobra co do nazw w tabeli.
Go to the top of the page
+Quote Post
trueblue
post
Post #14





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


O ile pamiętam, nazw kolumn też nie można bindować.
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 23.08.2025 - 07:52