Re: postgresql csv import

[email protected] (ourdiaspora)
Newsgroups php.general
Message-ID <CbsvpBpkHnCSrPBzPdAeEMxWKmyCSzDXhtUufFK5mIAprGGpIgNEIGhgXqnyg9TfliKYCXfPPVwPOQQa4_rHm_CqYv_D_NbJ9A5XF5GF3dk=@protonmail.com>
Readers,

Please could someone help to explain why the following code fails:

<?php
	$uploaddir = '~/tmp/cpac/cpactmp/';
	$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
	$dbconnect = pg_connect("dbname=cpacweb user=cpaca");
	$targetfilepath = $uploaddir . $uploadfile;
	if(isset($_POST["submit"])){
		$csvfile=$_FILES["userfile"]["tmp_name"];
		if($_FILES["userfile"]["tmp_name"] > 0) {
			$csvfileopen=fopen($csvfile, "r");
			while(($csvfiledata=fgetcsv($csvfileopen, 10000, ","))){
				$csvinsert = "INSERT into somedata(name, id, emailaddress, groupname) VALUES ('".$csvfiledata[0]."', '".$csvfiledata[1]."', '".$csvfiledata[2]."', '".$csvfiledata[3]."')";
				}
			}
			fclose($csvfileopen);
		}
	$query = "SELECT * FROM somedata";
	$result = pg_exec($dbconnect, $query);
	echo "Number of rows: " . pg_numrows($result);
	pg_freeresult($result);
	pg_close($dbconnect);
?>

The trial csv file contains 2 rows of data, but the query result is zero.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.