Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 14.02.2006, 05:58   #1
Firedaemon
Архивный участник
 
Join Date: Oct 2005
Posts: 267
Default [SHARE] Import itemname-e.txt into mySQL from PHP

Topic says all

[php:1:da72899f17]
<?php

$dblink = mysql_connect(, , );

($dblink) ? $dbselect = @mysql_select_db("") : DIE("Link to mySQL server could not be established.");

if (!$dbselect) DIE(mysql_error());

$row = 1;

$handle = fopen("itemname-e.txt", "r");

while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE)
{
$row++;

$query = "
INSERT INTO
`itemname-e`
SET
`id`=".$data[0].",
`name`='".addslashes($data[1])."',
`additionalname`='".addslashes($data[2])."',
`popup`='".$data[3]."',
`description`='".addslashes($data[4])."'
";

$result = mysql_query($query);

if ($result)
{
print $data[1]."\r\n";
}
else
{
print mysql_error();
sleep(30);
}
}

fclose($handle);
?>
[/php:1:da72899f17]

The SQL Schema
Code:
CREATE TABLE `itemname-e` (
  `id` int(12) NOT NULL,
  `name` varchar(255) NOT NULL,
  `additionalname` varchar(255) default NULL,
  `popup` int(2) NOT NULL,
  `description` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=ascii;
Firedaemon is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 17:58.