• DONATE to NULLED!
    Форуму и его команде можно помочь, мотивировать модераторов разделов.
    Помогите модератору этого раздела killoff лично.

Помощь Скрипт соединения баз

Статус
В этой теме нельзя размещать новые ответы.

diabl

Боцман
Регистрация
24 Мар 2009
Сообщения
438
Реакции
157
Вот есть скрипт, для соединения 2 баз.
У меня вопрос к знающим людям, что в этом скрипте не так?
Пробовал с конвертировать 2 базы dle 8.2
 
PHP:
$res2 = mysql_query("INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ($res[autor], $res[date], $res[short_story], $res[full_story], $res[xfields], $res[title], $res[descr], $res[keywords], 1, $res[alt_name], $res[comm_num], $res[allow_comm], $res[allow_main], $res[allow_rate], $res[approve], 0, $res[rating], $res[allow_br], $res[vote_num], $res[news_read], $res[votes], $res[access], $res[expires], $res[symbol], $res[flag], $res[editdate], $res[editor], $res[reason], $res[view_edit], $res[tags]",$cont2);

Может то ,что ты перепутал переменные $row и $res?
Кстати, лучше использовать цикл while..do а не do..while
 
Выходит ошибка

Удачно добавлено 0 строк
Всего 2537 ошибок

Warning: mysql_close(:( supplied argument is not a valid MySQL-Link resource in Z:\home\test1.ru\www\bd.php on line 39

Добавлено через 1 минуту
Я в этом слад, не могли бы Вы мне помочь
 
Правильно

ты закрывашь коннект

PHP:
mysql_close($cont);

А переменная коннекта у тебя
PHP:
$cont1
 
Правильно
ты закрывашь коннект
PHP:
mysql_close($cont);
А переменная коннекта у тебя
PHP:
$cont1


Это я исправил,теперь

Удачно добавлено 0 строк
Всего 2537 ошибок

не добавляться, вот код как я изменил:


 
А взять в кавычки вставляемые данные?
Вот измененный запрос:

Код:
$row2 = mysql_query("INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('$row[autor]', '$row[date]', '$row[short_story]', '$row[full_story]', '$row[xfields]', '$row[title]', '$row[descr]', '$row[keywords]', 1, '$row[alt_name]', '$row[comm_num]', '$row[allow_comm]', '$row[allow_main]', '$row[allow_rate]', '$row[approve]', 0, '$row[rating]', '$row[allow_br]', '$row[vote_num]', '$row[news_read]', '$row[votes]', '$row[access]', '$row[expires]', '$row[symbol]', '$row[flag]', '$row[editdate]', '$row[editor]', '$row[reason]', '$row[view_edit]', '$row[tags]'", $cont2);

+ здесь нельзя использовать цикл do .. while (на первой итерации вставляется пустая строка).

+ добавил отладку:

Код:
<?php 
$CONFIG['dbaddress1'] = "localhost"; // Хост, по умолчанию localhost 
$CONFIG['dbuser1']    = "12345";      // Логин к базе данных 1 
$CONFIG['dbpass1']     = "12345";     // Пароль к базе данных 1 
$CONFIG['dbname1']     = "12345";       // База данных 1 

$CONFIG['dbaddress2'] = "localhost"; // Хост, по умолчанию localhost 
$CONFIG['dbuser2']    = "diabl";      // Логин к базе данных 2 
$CONFIG['dbpass2']     = "diabl1988";     // Пароль к базе данных 2 
$CONFIG['dbname2']     = "diabl";       // База данных 2 

$cont1=mysql_connect($CONFIG['dbaddress1'],$CONFIG['dbuser1'],$CONFIG['dbpass1'])or die("База недоступна"); 
mysql_select_db($CONFIG['dbname1'],$cont1); 
$res = mysql_query("SELECT * FROM dle_post",$cont1); 

$cont2=mysql_connect($CONFIG['dbaddress2'],$CONFIG['dbuser2'],$CONFIG['dbpass2'])or die("База недоступна"); 
mysql_select_db($CONFIG['dbname2'],$cont2); 

$success = 0; 
$bad = 0; 
$errors = '';

while ( $row=mysql_fetch_row($res) ) 
{ 
	$sql_query = "INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('$row[autor]', '$row[date]', '$row[short_story]', '$row[full_story]', '$row[xfields]', '$row[title]', '$row[descr]', '$row[keywords]', 1, '$row[alt_name]', '$row[comm_num]', '$row[allow_comm]', '$row[allow_main]', '$row[allow_rate]', '$row[approve]', 0, '$row[rating]', '$row[allow_br]', '$row[vote_num]', '$row[news_read]', '$row[votes]', '$row[access]', '$row[expires]', '$row[symbol]', '$row[flag]', '$row[editdate]', '$row[editor]', '$row[reason]', '$row[view_edit]', '$row[tags]'";
	$row2 = mysql_query($sql_query, $cont2);

	if (mysql_errno($cont2))
	{
		$errors .= "MySQL error ".mysql_errno( $cont2 ).": ".mysql_error($cont2)."\n<br>When executing:<br>\{$sql_query}\n<br>";
		$bad++;
	}
	else 
	{ 
		$success++; 
	} 
} 

echo '<html>';
echo "Удачно добавлено ".$success." строк<br>"; 
echo "Всего ".$bad." ошибок<br>"; 
echo $errors;

mysql_close($cont1); 
mysql_close($cont2); 

?>
 
А взять в кавычки вставляемые данные?
Вот измененный запрос:
Код:
$row2 = mysql_query("INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('$row[autor]', '$row[date]', '$row[short_story]', '$row[full_story]', '$row[xfields]', '$row[title]', '$row[descr]', '$row[keywords]', 1, '$row[alt_name]', '$row[comm_num]', '$row[allow_comm]', '$row[allow_main]', '$row[allow_rate]', '$row[approve]', 0, '$row[rating]', '$row[allow_br]', '$row[vote_num]', '$row[news_read]', '$row[votes]', '$row[access]', '$row[expires]', '$row[symbol]', '$row[flag]', '$row[editdate]', '$row[editor]', '$row[reason]', '$row[view_edit]', '$row[tags]'", $cont2);
+ здесь нельзя использовать цикл do .. while (на первой итерации вставляется пустая строка).
+ добавил отладку:
Код:
<?php 
$CONFIG['dbaddress1'] = "localhost"; // Хост, по умолчанию localhost 
$CONFIG['dbuser1']    = "12345";      // Логин к базе данных 1 
$CONFIG['dbpass1']     = "12345";     // Пароль к базе данных 1 
$CONFIG['dbname1']     = "12345";       // База данных 1 
$CONFIG['dbaddress2'] = "localhost"; // Хост, по умолчанию localhost 
$CONFIG['dbuser2']    = "diabl";      // Логин к базе данных 2 
$CONFIG['dbpass2']     = "diabl1988";     // Пароль к базе данных 2 
$CONFIG['dbname2']     = "diabl";       // База данных 2 
$cont1=mysql_connect($CONFIG['dbaddress1'],$CONFIG['dbuser1'],$CONFIG['dbpass1'])or die("База недоступна"); 
mysql_select_db($CONFIG['dbname1'],$cont1); 
$res = mysql_query("SELECT * FROM dle_post",$cont1); 
$cont2=mysql_connect($CONFIG['dbaddress2'],$CONFIG['dbuser2'],$CONFIG['dbpass2'])or die("База недоступна"); 
mysql_select_db($CONFIG['dbname2'],$cont2); 
$success = 0; 
$bad = 0; 
$errors = '';
while ( $row=mysql_fetch_row($res) ) 
{ 
	$sql_query = "INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('$row[autor]', '$row[date]', '$row[short_story]', '$row[full_story]', '$row[xfields]', '$row[title]', '$row[descr]', '$row[keywords]', 1, '$row[alt_name]', '$row[comm_num]', '$row[allow_comm]', '$row[allow_main]', '$row[allow_rate]', '$row[approve]', 0, '$row[rating]', '$row[allow_br]', '$row[vote_num]', '$row[news_read]', '$row[votes]', '$row[access]', '$row[expires]', '$row[symbol]', '$row[flag]', '$row[editdate]', '$row[editor]', '$row[reason]', '$row[view_edit]', '$row[tags]'";
	$row2 = mysql_query($sql_query, $cont2);
	if (mysql_errno($cont2))
	{
		$errors .= "MySQL error ".mysql_errno( $cont2 ).": ".mysql_error($cont2)."\n<br>When executing:<br>\{$sql_query}\n<br>";
		$bad++;
	}
	else 
	{ 
		$success++; 
	} 
} 
echo '<html>';
echo "Удачно добавлено ".$success." строк<br>"; 
echo "Всего ".$bad." ошибок<br>"; 
echo $errors;
mysql_close($cont1); 
mysql_close($cont2); 
?>




Теперь выдаёт ошибки в запросе:


PHP:
Удачно добавлено 0 строк
Всего 2536 ошибок
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When executing:
\{INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('', '', '', '', '', '', '', '', 1, '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', ''}
 
Забыл закрывающую скобку )
должно быть так

PHP:
$sql_query = "INSERT INTO dle_post (autor, date, short_story, full_story, xfields, title, descr, keywords, category, alt_name, comm_num, allow_comm, allow_main, allow_rate, approve, fixed, rating, allow_br, vote_num, news_read, votes, access, expires, symbol, flag, editdate, editor, reason, view_edit, tags) VALUES ('$row[autor]', '$row[date]', '$row[short_story]', '$row[full_story]', '$row[xfields]', '$row[title]', '$row[descr]', '$row[keywords]', 1, '$row[alt_name]', '$row[comm_num]', '$row[allow_comm]', '$row[allow_main]', '$row[allow_rate]', '$row[approve]', 0, '$row[rating]', '$row[allow_br]', '$row[vote_num]', '$row[news_read]', '$row[votes]', '$row[access]', '$row[expires]', '$row[symbol]', '$row[flag]', '$row[editdate]', '$row[editor]', '$row[reason]', '$row[view_edit]', '$row[tags]')";

И замени

PHP:
while ( $row=mysql_fetch_row($res) )

на
PHP:
while ( $row=mysql_fetch_assoc($res) )
 
Статус
В этой теме нельзя размещать новые ответы.
Назад
Сверху