Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   [SHARE] Import itemname-e.txt into mySQL from PHP (https://postpacific.loc-online.com/showthread.php?t=3344)

Firedaemon 14.02.2006 05:58

[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 14.02.2006 06:00

oh, and I should comment that this script assumes you have removed all the field information like "id=" and "name=[]" etc

If you want to store that info in the mysql table, the script can easily import it but you will need to change the data types in the mysql table so it can be stored properly.

Alien003 14.02.2006 06:39

Isn't it much easy using the php from the php decryptor?
its not so easy to erase all the field information ...

Firedaemon 15.02.2006 04:11

Sure, if thats all you plan on doing. Personally, I have the entire client dats in mySQL. I am then able to create programs that perform a wide variety of tasks automatically for me. I also do the same thing with ALL of the server files as well. This allows me to easily sync changes when new versions of l2 come out and etc.


All times are GMT. The time now is 15:25.