Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407

    PDO bindParam e data type..

    Ciao ragazzi, non riesco a capire il funzionamento (o meglio a cosa serve) l'opzione data_type nel costrutto PDO::bindParam, ovvero:

    bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type [, int $length [, mixed $driver_options ]]] )
    Cioè, se io ho una cosa del tipo
    Codice PHP:
    $kill "Beverly Carran";
    $delete->bindParam(1$killPDO::PARAM_INT);
    $delete->execute(); 
    specificare il tipo di parametro (intero) a cosa serve, visto che anche se gli dò una stringa funziona uguale?
    Non dovrebbe dare un errore, o qualcosa del genere?

    Ho provato a googlare, e sempre su php.net ho trovato un altro post (senza risposte) che rispecchia esattamente il mio problema:

    Hi all,

    I am currently working on PDO. Exactly on the bindParam() function.
    The third parameter data_type seems to be here to force the type of the
    value ?
    But when I try :

    $sql = "INSERT INTO produit (idproduit, nom, marque)
    VALUES (NULL, :nom, :marque)";
    $stmt = $dbh->prepare($sql);

    $nom = 'Testarossa';
    $marque = 'Ferrari' ;

    $stmt->BindValue(':marque',$marque) ;
    $stmt->BindParam(':nom',$nom,PDO::PARAM_INT) ;

    $stmt->execute();
    $nom = '250 GTO' ;
    $stmt->execute();
    ?>


    I was expecting to have either a PHP error or an interger in my
    database. But in my DB I have :

    22 Testarossa Ferrari
    23 250 GTO Ferrari

    It mean that it didn't change if I have the third parameter or not. Or
    perhaps I miss something. Can someone tole me more ? Or just can someone
    told me where I can find information about it.

    Regards,

    Cyruss
    sbaglio qualcosa?
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

  2. #2
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407
    ...sono l'unico che utilizza PDO?
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.