Re: Prepared statements

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

 



Anthony Ettinger wrote:
> On 3/4/06, Julius Hacker <julius@xxxxxxxxxxxxxx> wrote:
>   
>> One other thing:
>> If I do the bind_param within the loop, it just works.
>>
>> The curious is that I have to prepared statements for this loop (one for
>> inserting data and one for updating data) and the one for updating data
>> works and that for inserting don't.
>> Both statements are 100% valid.
>>
>> Julius Hacker wrote:
>>     
>>> Hi,
>>>
>>> so I need help again:
>>> I want to use prepared statements to insert lots of data in my
>>> MySQL-database.
>>> For that I use foreach because I have an array containing all necessary
>>> information.
>>>
>>> Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and
>>> mysql_stmt_bind_param.
>>> In the foreach-loop I give the variables, which I bound with bind_param,
>>> their values and want to execute the statement.
>>>
>>> But now MySQL returns always an error.
>>> It seems that the values I gave the variables in the loop aren't used
>>> because I used bind_param before that.
>>>
>>> In the example for mysql_bind_param they do it like me.
>>> Is the example also wrong or do I have to consider something special?
>>>
>>> --
>>> Regards
>>> Julius Hacker
>>>
>>> http://www.julius-hacker.de
>>> julius@xxxxxxxxxxxxxx
>>>
>>> OpenPGP-Key-ID: 0x4B4A486E
>>>
>>>
>>>       
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>>     
>
> Can you dump the error string reported back from the mysql database
> connection? Could provide some insight as to why your INSERT fails,
> and the UPDATE works.
>   
MySQL returns "Column 'auction_house' cannot be null".
Here're some parts of my code:

--- code ---

$update = $this->sql->stmt_init();
$update->prepare("UPDATE auctions SET name=?, auction_house=?, link=?,
prize=?, runtime=?, bids=?, picture=? WHERE link=?");
$update->bind_param("sisdsiss", $auction_parts["name"],
$auction_house["id"], $auction_parts["link"], $auction_parts["prize"],
$auction_parts["runtime"], $auction_parts["bids"],
$auction_parts["picture"], $auction_parts["link"]);
       
$insert = $this->sql->stmt_init();
$insert->prepare("INSERT INTO auctions (auction_house, name, link,
prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)");
$insert->bind_param("issdsis", $auction_house["id"],
$auction_parts["name"], $auction_parts["link"], $auction_parts["prize"],
$auction_parts["runtime"], $auction_parts["bids"],
$auction_parts["picture"]);

--- /code ---

after this, there's the loop, in which I do either $update->execute();
or $insert->execute(); - the $update->execute(); runs without problems
but the $insert->execute runs into the described problem.

--
Regards
Julius Hacker
       

-- 
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