mysql - PHP load csv into sql table only works when all permissions granted @localhost -
this question has been asked no answers yet...
have csv upload form load existing mysql table use on drupal page, hence being in 1 php. have (thanks coyotelab):
$mysqli = new mysqli($server, $user, $password, $database); if ($mysqli->connect_error) { die("failed connect: " . $mysqli->connect_error); } if (isset($_post['submit'])) { if (is_uploaded_file($_files['filename']['tmp_name'])) { echo "<h2>" . "file ". $_files['filename']['name'] ." uploaded successfully." . "</h2>"; } $handle = fopen($_files['filename']['tmp_name'], "r"); if ($handle !== false) { $import="load data local infile '" . $_files['filename']['tmp_name'] . "' table demo2 character set 'utf8' fields terminated ',' optionally enclosed '\"' ignore 1 lines;"; mysql_query($import) or die('<p style="color:red;">database import unsuccessful: ' . mysql_error() . '</p>'); } fclose($handle); print "<p style='color:blue;'>import done</p>"; echo "<p style='position: relative; top: 10px;'><strong>displaying contents:</strong></p>"; readfile($_files['filename']['tmp_name']); unset($_post); } else { print "<p>import new csv</p>\n"; print "<form enctype='multipart/form-data' action='?q=drupal-relative-path-to/upload.php' method='post'>\n"; print "<input size='50' type='file' name='filename'><br />\n"; print "<input type='submit' name='submit' value='import'></form>"; at first, form test locally , granting permissions localhost worked , data imported successfully. on drupal server, there no change localhost permissions. other forms insert sql data have worked fine drupal pages. happens upload file function.
so far form shows on drupal, when uploading , submitting csv, same error testing on localhost without permissions. error "no database selected"
my thought change location uploaded temp files live, though haven't figured out or might not possible on drupal server. tried adding second db connect line, doesn't work. must have temp directory.
this form on private network.
if error "no database connection" code fails on first code row displayed here. wrong database user account information (or account self). maybe host isn't "localhost" else?
if drupal working check out it's connection. check file /sites/default/settings.php. there stored information database connection can copy account data there.
btw, instead of old school fopen on php have easier use file_get_contents() function.
Comments
Post a Comment