Changing unpk/pk function to database based in phpizabi

ok here is some ideas to do it. I have done it. But i don’t use phpizabi any more. I have developed my own script. And i had transferred the users, contacts, user gallery to my new script using this method so it can be used by you to convert the phpizabi contact, gallery system to database based.
Below is how databse structure will be like for contact and gallery system:

CREATE TABLE IF NOT EXISTS `phpizabi_contact` (
`id` int(9) NOT NULL auto_increment,
`user` int(9) NOT NULL,
`friend` int(9) NOT NULL,
`date` int(32) NOT NULL,
`is_blocked` tinyint(1) NOT NULL default '0',
PRIMARY KEY  (`id`)
) ENGINE=MyISAM ;

CREATE TABLE IF NOT EXISTS `phpizabi_contact_request` (
`id` int(9) NOT NULL auto_increment,
`for_user` int(9) NOT NULL,
`from_user` int(9) NOT NULL,
`date` int(32) NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM ;

-- --------------------------------------------------------

--
-- Table structure for table `phpizabi_gallery`
--

CREATE TABLE IF NOT EXISTS `phpizabi_gallery` (
`id` int(11) NOT NULL auto_increment,
`user` int(10) NOT NULL default '0',
`img` varchar(100) NOT NULL default '0',
`date` int(32) NOT NULL,
`album_id` int(32) NOT NULL default '0',
`title` varchar(250) NOT NULL default '',
`description` longtext NOT NULL,
`views` int(10) NOT NULL default '0',
`comments` int(10) NOT NULL default '0',
`rating` float NOT NULL default '0',
`votes` int(11) NOT NULL default '0',
`is_mainpicture` tinyint(1) NOT NULL default '0',
PRIMARY KEY `id` (`id`),
FULLTEXT KEY `title` (`title`,`description`)
) ENGINE=MyISAM ;

CREATE TABLE IF NOT EXISTS `phpizabi_gallery_album` (
`id` int(11) NOT NULL auto_increment,
`user` int(10) NOT NULL default '0',
`date` int(64) NOT NULL default '0',
`cover_img` varchar(64) NOT NULL,
`album_name` varchar(20) NOT NULL default '',
`album_description` text NOT NULL,
PRIMARY KEY `id` (`id`),
FULLTEXT KEY `album_name` (`album_name`,`album_description`)
) ENGINE=MyISAM ;

Now to load the contents of the users from the old phpizabi database to new tables we can use the following script.
Inserting pictures to new gallery table.

$sql = myQ("SELECT `id`,`pictures`, `username` FROM `[x]users`");
while($row = myF($sql)){
$pictures = unpk($row["pictures"]);
if (!is_array($pictures)) $pictures = array();

foreach ($pictures as $pic) {
myQ("
INSERT INTO `[x]gallery` (`user`,`img`,`date`,`title`,`description`,`is_mainpicture`)
VALUES
('{$row["id"]}','{$pic["FILE"]}','".time()."','{$pic["NAME"]}','{$pic["DESCRIPTION"]}','{$pic["MAIN"]}')
");
}
}

Inserting contacts to new table:

$sql = myQ("SELECT `id`,`contacts` FROM `[x]users`");
while($row = myF($sql)){
$contacts = unpk($row["contacts"]);
if (!is_array($contacts)) $contacts = array();

foreach ($contacts as $groupName => $usersArray) {

if (is_array($usersArray)) foreach ($usersArray as $userArrayKey => $userEntity) {
myQ("
INSERT INTO `[x]contact` (`user`,`friend`,`date`)
VALUES
('{$row["id"]}','{$userEntity}','".time()."')
");

}
}

This should now transfer all the contacts and gallery pictures to the new table. I think i have covered the main part where you were confused about. After you get the informations in a table. You can code php to function with contact and gallery system. i hope it will be helpful.

This entry was posted in php, phpizabi. Bookmark the permalink.

5 Responses to Changing unpk/pk function to database based in phpizabi

  1. Johnn says:

    Hey thanks a lot, I will try this out and hopefully not stumble!

  2. Jazen says:

    Hi Yalamber,

    Could you please give an example of either contacts.php page or gallery, or some similar code, where it’s coded in such a way to use your suggested database structure.
    I’m thinking if we had a full page example, of perhaps what code looked like before, verses code with changes to use this database table, then we might be able to take that information and know how to go about changing other pages as well, using your php code example as a reference.

    Thanks,
    Jazen

  3. yalamber says:

    @jazen
    Hello,
    The main view of this article was to provide a way to extract information for cotact and gallery from phpizabi database and store them to their respective table. You can then code the part to add, delete, block, manage contacts. Also code part for gallery, upload, delete, album parts. I can provide some codes by monday.
    thanks

  4. Tony says:

    Any more on this? I could really use a little more direction on how to implement the last half of that code. I’ve got the database built, I’m just having trouble pulling the old user data and putting it in the new table.

    • yalamber says:

      Hey we can write a sccript to import old data to new tables. First see how array are saved in the old database tables and extract infos from there and pull it to new database.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>