RE: Doubts concerning a general Insert method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nice. :-) Thanks a lot Stuart for your time and explanations. 
Now that I have understand, I will try to move on, and understand how can we introduce bindParams on it:

For a recall, here is the original class:

> public function dbInsert($table, $values) {
>
>        $this->conn();
>
>        $fieldnames = array_keys($values[0]);
>
>        $size = sizeof($fieldnames);
>
>        $i=1;
>
>        //construction of the prepared statment
>        $sql = "INSERT INTO $table";
>
>        $fields = '( ' . implode(' ,', $fieldnames) . ' )';
>
>        $bound = '(:' . implode(', :', $fieldnames) . ' )';
>
>        $sql .= $fields.' VALUES '.$bound;
>
>        //prepares statement e saves it on variable $stmt
>        $stmt = $this->db->prepare($sql);
>
>        foreach($values as vals)
>        {
>                $stmt->execute($vals);
>        }
> }


However I do have some questions that maybe someone more experimented then me could easily solve:

1)
The bindParams should look similar to this:

$stmt->bindParam(':animal_name', $animals->getName(), PDO::PARAM_STR );
$stmt->bindParam(':animal_type', $animals->getType(), PDO::PARAM_STR );

So, instead of looping trough an array of values, I will to do it for objects, something like:
foreach($animals->listaAnimals() as $row) ...

Can I have some words on this so that I can properly try to add bindParam on this class method.

2)
I also need to have a way to add PDO::PARAM_STR if the values is a string or PDO::PARAM_INT if the values is int, PDO::PARAM_BOOL etc... 
Is there a way to control this? Using something like is_integer() and is_string(), inside if statement perhaps? If so, what about the Boolean?


Thanks a lot,
Márcio







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux