0

I want to import my local database dump to server phpmyadmin.For that first i export whole database dump as db-backup-2016-09-14 14.25.11.sql file.after tht i tried to import this sql file to my server phpmyadmin.Below is my code

<?php
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d");
$time = date("Y-m-d H:i:s");

import_tables();

function import_tables()
{
$filename = 'db-backup-2016-09-14 14.25.11.sql';
$mysql_host = '192.168.1.1';
$mysql_username = 'databaseuser';
$mysql_password = 'databasepassword';
$mysql_database = 'databasename';
$conn=mysqli_connect($mysql_host, $mysql_username, $mysql_password,$mysql_database) or die('Error connecting to MySQL server: ' . mysqli_error($conn));
mysqli_select_db($conn,$mysql_database) or die('Error selecting MySQL database: ' . mysqli_error($conn));
$templine = '';
$lines = file($filename);
foreach ($lines as $line)
{
if (substr($line, 0, 2) == '--' || $line == '')
    continue;
$templine .= $line;
if (substr(trim($line), -1, 1) == ';')
{
    mysqli_query($conn,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysqli_error($conn) . '<br /><br />');
    $templine = '';
}
}
 echo "Tables imported successfully";
}
?>

Here the hostname declared is my server IP address and username password which i given in mysql database username password created in server.For this im getting error like

enter image description here

Problem with the connection to server.If anybody knows solution please help me to get out of this problem.Thanks in advance

Shiv Singh
  • 6,431
  • 3
  • 39
  • 47
Kavya Shree
  • 942
  • 2
  • 13
  • 50
  • Those aren't your real connection details, right? – Jonnix Sep 15 '16 at 08:16
  • 1
    I'm not even sure why you're doing this if you want to use phpmyadmin. Just import the file that you apparently already have. Or use the mysql CLI tool to import the file. There is no point in having this PHP code afaics. – Jonnix Sep 15 '16 at 08:17
  • In my application if the user working in local server after inserted all details simply on click of backup it should export from local server data and imported in server database for tht im using PHP – Kavya Shree Sep 15 '16 at 08:23
  • Look at the demo provided here http://stackoverflow.com/questions/19751354/how-to-import-sql-file-in-mysql-database-using-php – Sasikumar Sep 15 '16 at 08:25
  • Problem is I can import in local..I cant import to server PHPmyadmin. In above link also refered there thy tried to import in local only – Kavya Shree Sep 15 '16 at 08:29
  • This is not a problem with your code. Something is preventing you from connecting to your MySQL server. Contact your web host for details. –  Sep 17 '16 at 05:00
  • Image shows that you are running script on your local network (Windows). So, i think, that your local IP it's not in firewall or not authorized on cpanel's mysql server. https://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html#error_cr_connection_error – abkrim Sep 17 '16 at 05:11
  • first of all never use real details on any public place like your question – Shiv Singh Sep 20 '16 at 05:03

2 Answers2

0

first of all you should enable remote connection on Mysql database and its look like you are using cPanel than you should do it by cPanel => Remote MySQL and set % for all otherwise put accessing server IP

Once Remote access has been enabled than you can access,

Note: Some time it could be not work due to firewall port block so contact hosting provider to allow on firewall

Shiv Singh
  • 6,431
  • 3
  • 39
  • 47
-1

It may have some reasons. For example, maybe you use a shared server, and in shared servers you have some limitations for the size of your database.... However, if you have an access to PHP.ini you can also fix the problem with the following way:

try to access to PHP.ini. It is mostly located in /etc/php5/apache2/php.ini or other paths on your server.. of course you need a permission! Sometime hosting services provide access to this file for their customers...

Next, search for the post_max_size entry, and enter a larger number than the size of your database (15M in this case), for example:

post_max_size = 25M

Next edit the entry for memory_limit and give it a larger value than the one given to post_max_size.

The order from biggest to smallest should be:

    memory_limit
    post_max_size
    upload_max_filesize

I hope it helps you.

Ashouri
  • 878
  • 4
  • 19
  • Memory is not the problem.Actually connection is not working I jsut want to know how can i connect with cpanel mysql database server – Kavya Shree Sep 15 '16 at 10:39
  • I think not correct reply. Images show question about HY000/2002. That it's not issue about memory or php leaks. https://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html#error_cr_connection_error – abkrim Sep 17 '16 at 05:14