0

I have completed a WordPress project(localhost) and uploaded to web using core FTP LE.The issue is I am not getting any cpnael detail from the client to to import the database which I created in Localhost...Is there any way to proceed ?[Tried in google but did not find suitable solution]I am getting error

Error establishing a database connection probably bcaz of that

Note:I received only FTP details and Database details.But did not get cPanel detail

Kindly do help me.Thanks in Advance..

  • Yes here are many ways to do that. Let me know you have FTP access and Database user pass db name and all details – Navnish Bhardwaj Sep 10 '15 at 07:14
  • @NavnishBhardwaj ,Kindly send me the links..Plz. – Hello World Sep 10 '15 at 07:15
  • What do you need to import exactly? – vard Sep 10 '15 at 07:21
  • Hi, might this question be better asked in serverfault instead of stackoverflow - it's an administration issue and the folks over there might now more about it. – L-Ray Sep 10 '15 at 07:24
  • @vard ,The mysql database which I created into server without Cpanel – Hello World Sep 10 '15 at 07:24
  • If it's the whole database it's way too much risks to import it through a custom script. If it fails for some reason (execution timeout for example) you gonna break the whole website. I suggest to tell your client to import the database himself if he doesn't want to share the cpanel details (btw he can easily create a user on cpanel with limited rights). It's not a proper way to work otherwise. – vard Sep 10 '15 at 07:28
  • time execution possible modify on script. On fact, phpmyadmin get same problem. For me also import large databases on shell. But @Hello World assk for scenario. First he needs database, user with permission for this database, mysqldump of database. Upload FTP, create SIMPLE script php for restore mysqldump on this database. Also I think "Kindly send me the links..Plz" it's not security flavor... – abkrim Sep 10 '15 at 09:42

2 Answers2

0

You can upload a certain PHP script to the server which imports the data to the database like BigDump or write your own script

Community
  • 1
  • 1
Harshit
  • 5,147
  • 9
  • 46
  • 93
0

You can run this code on server attach the file and here you go with import.

<html>
<head>
<style type="text/css">
body {
    background: #E3F4FC;
    font: normal 14px/30px Helvetica, Arial, sans-serif;
    color: #2b2b2b;
}
a {
    color:#898989;
    font-size:14px;
    font-weight:bold;
    text-decoration:none;
}
a:hover {
    color:#CC0033;
}

h1 {
    font: bold 14px Helvetica, Arial, sans-serif;
    color: #CC0033;
}
h2 {
    font: bold 14px Helvetica, Arial, sans-serif;
    color: #898989;
}
#container {
    background: #CCC;
    margin: 100px auto;
    width: 945px;
}
#form           {padding: 20px 150px;}
#form input     {margin-bottom: 20px;}
</style>
</head>
<body>
<div id="container">
<div id="form">

<?php

include "inc/database.php"; //Connect to Database

//Upload File
if (isset($_POST['submit'])) {
    if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
        echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
        echo "<h2>Displaying contents:</h2>";
        readfile($_FILES['filename']['tmp_name']);
    }

    //Import uploaded file to Database
    $handle = fopen($_FILES['filename']['tmp_name'], "r");

    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $import="INSERT into awards (award_name, award_level, award_description, award_photo) values('$data[0]','$data[1]','$data[2]','$data[3]')";

        mysql_query($import) or die(mysql_error());
    }

    fclose($handle);

    print "Import done";

    //view upload form
}else {

    print "Upload new csv by browsing to file and clicking on Upload<br />\n";

    print "<form enctype='multipart/form-data' action='import-award.php' method='post'>";

    print "File name to import:<br />\n";

    print "<input size='50' type='file' name='filename'><br />\n";

    print "<input type='submit' name='submit' value='Upload'></form>";

}

?>

</div>
</div>
</body>
</html>
Navnish Bhardwaj
  • 1,687
  • 25
  • 39
  • This code import a csv in a table named `award`, so OP will have to change this script depends of his input data. – vard Sep 10 '15 at 07:20
  • mysql_query it's obsolete php > 5.5.0 and delete on PHP 7. http://php.net/manual/es/function.mysql-query.php – abkrim Sep 10 '15 at 09:43