Re: Inserting into multiple tables

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

 



Adam

Thanks for your reply, but I think I am totally confused. Not so much by your answer (although I admit I did not get it to work yet), but by the entire multiple table issue. Several books I use talk about the importance of using multiple tables, yet are thin on the insert issue. Searching the web I have read several answers saying you simply cant insert into multiple tables at once.

So if multiple tables is such an important issue, why is there no insert solution. What am I missing?

Gary


"Adam Richardson" <simpleshot@xxxxxxxxx> wrote in message news:x2ge4d8ea9d1004101457r62b7c0b8uc3673353c3758394@xxxxxxxxxxxxxxxxx
On Sat, Apr 10, 2010 at 5:27 PM, Gary <gwpaul@xxxxxxx> wrote:

I am experimenting with multiple tables, it is only a test that is my local machine only. This is the current code, which does not work , I have tried
to concatonate the insert statements.  I have tried multiple $query
variables, but it is just overwriting itself (only the last one gets
inserted). I also tried writing the $query as an array, which got me an
error message (saying it was expecting a string and I offered an array).

Someone point me in the right direction?


I'm not aware of any multi-table insert syntax:
http://lists.mysql.com/mysql/171921

You'd have to perform 4 separate mysql_query() calls to accomplish what
you're looking for (one for each insert.)

That said, I'd recommend using a transaction so you make sure all of the
inserts succeed or fail together (it would cause issues down the road if one table insert worked and another failed.) Additionally, I'd recommend using prepared statements to avoid SQL injection (I'd mention validation your POST
data, too ;)

See the tutorial below:
http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html

Adam

--
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 5016 (20100410) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature database 5016 (20100410) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




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