Heim  >  Artikel  >  Backend-Entwicklung  >  CSV插入数据库如何查看没有插入成功的数据

CSV插入数据库如何查看没有插入成功的数据

WBOY
WBOYOriginal
2016-06-23 13:59:411000Durchsuche

读取一个csv的时候插入数据库,发现有些插入成功了,有些没有插入成功,怎么样看那些没有插入成功的呢

我的PHP代码是这样的

  <?php	$link=mysql_connect('localhost','roots','2014222')or die('不能连接到数据库');	mysql_select_db('numdata',$link)or die('不能选择数据库numdata');	mysql_query('set names utf8');		$file=fopen('u5.csv','r');		while($out=fgetcsv($file)){		$sql="insert into pro values(null,'{$out[0]}','{$out[1]}','{$out[2]}','{$out[3]}','{$out[4]}','{$out[5]}','{$out[6]}','{$out[7]}','{$out[8]}','{$out[9]}','{$out[10]}','{$out[11]}','{$out[12]}','{$out[13]}','{$out[15]}','{$out[16]}','{$out[17]}','{$out[18]}')";			if(mysql_query($sql)){				$row++;			}		//echo $sql;		echo '成功插入<h1>'.$row.'</h1>条数据';		}?>


回复讨论(解决方案)

if(mysql_query($sql)){                $row++;}else{      echo $sql;  //输出执行失败的sql}

进行判断插入失败的写入一个日志文件中

if(mysql_query($sql)){                $row++;}else{      echo $sql;  //输出执行失败的sql}


哎呀,你太聪明了,谢谢,非常感谢,为什么我没想到这个呢

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn