开发者

Insert array into database

开发者 https://www.devze.com 2023-02-17 17:05 出处:网络
I\'m using zend to insert fields into a database like so $row->title = $title; 开发者_运维技巧$row->description = $description

I'm using zend to insert fields into a database like so

$row->title = $title;
开发者_运维技巧$row->description = $description
etc etc

I want the next line to be:

$row->images = $images;    // where $images is an array

Then I'm calling the save function:

$row->save;

Is there anyway I can input that array?

I was going to loop through it but that won't work as I'd have to save the row X times where X is the amount of images and that just doesn't fit with the way zend wants me to insert data into the db.

Any ideas?


There's not an easy way to do it, but one way you could handle it (which I've done before) is make images a text field, and then json_encode($images) before inserting it.

You'd of course have to json_decode it when you got it back out, and you can't really index like that, but it's a thought.

Alternatively, you might rethink your problem here. You could always have another table which stores the images, and has a reference id back to your first table.


You can also store them as serialized value and use them after unserializing

serialze($array) and unserialize($array)

0

精彩评论

暂无评论...
验证码 换一张
取 消