how to connect to web host mysql db from localhost












0















I have a problem to connect to my webhost MYSQL from my localhost.



I have a host (www.printcity24.com) with mysql db and I use this code to connect to mysql db :



<?php
$db_path = mysqli_connect('printcity24.com', 'myuser', 'mypass', 'mydb', '3306');
if(!$db_path) {
echo mysqli_connect_error();
}else{
echo "Connected successfully";
}

?>


when i call this code from printcity24.com every thing is OK and connect to mysql db successfully.



but i created a localhost by xampp on my computer and when i call this code i got this error :




Warning: mysqli_connect(): MySQL server has gone away in C:Program
FilesXAMPPhtdocsindex.php on line 2



Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in
C:Program FilesXAMPPhtdocsindex.php on line 2 MySQL server
has gone away






I talk to my web host admin and opened 3306 port on my host and added % to Manage Access Hosts on CPanel > remote MYSQL



but i still have problem to connection.










share|improve this question























  • Can you use a tool such MySQL WorkBench to connect to your remote DB?

    – Cid
    Nov 20 '18 at 15:11











  • why should i use MySQL WorkBench ? does it better than xampp? i dont know how to use it.

    – S R R
    Nov 20 '18 at 15:23






  • 1





    It has nothing to do with xamp. It's a tool to manage your MySQL databases. You can use it to check if you can remotly connect to your db

    – Cid
    Nov 20 '18 at 15:25











  • To add to what Cid said, the purpose of doing so is to rule out the possibility of an issue in your PHP code, since Workbench is known to connect properly to Mysql.

    – ADyson
    Nov 20 '18 at 15:25













  • Another thing to try is explicitly adding your (public) IP address to the allowed hosts lists, rather than just %.

    – ADyson
    Nov 20 '18 at 15:26
















0















I have a problem to connect to my webhost MYSQL from my localhost.



I have a host (www.printcity24.com) with mysql db and I use this code to connect to mysql db :



<?php
$db_path = mysqli_connect('printcity24.com', 'myuser', 'mypass', 'mydb', '3306');
if(!$db_path) {
echo mysqli_connect_error();
}else{
echo "Connected successfully";
}

?>


when i call this code from printcity24.com every thing is OK and connect to mysql db successfully.



but i created a localhost by xampp on my computer and when i call this code i got this error :




Warning: mysqli_connect(): MySQL server has gone away in C:Program
FilesXAMPPhtdocsindex.php on line 2



Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in
C:Program FilesXAMPPhtdocsindex.php on line 2 MySQL server
has gone away






I talk to my web host admin and opened 3306 port on my host and added % to Manage Access Hosts on CPanel > remote MYSQL



but i still have problem to connection.










share|improve this question























  • Can you use a tool such MySQL WorkBench to connect to your remote DB?

    – Cid
    Nov 20 '18 at 15:11











  • why should i use MySQL WorkBench ? does it better than xampp? i dont know how to use it.

    – S R R
    Nov 20 '18 at 15:23






  • 1





    It has nothing to do with xamp. It's a tool to manage your MySQL databases. You can use it to check if you can remotly connect to your db

    – Cid
    Nov 20 '18 at 15:25











  • To add to what Cid said, the purpose of doing so is to rule out the possibility of an issue in your PHP code, since Workbench is known to connect properly to Mysql.

    – ADyson
    Nov 20 '18 at 15:25













  • Another thing to try is explicitly adding your (public) IP address to the allowed hosts lists, rather than just %.

    – ADyson
    Nov 20 '18 at 15:26














0












0








0








I have a problem to connect to my webhost MYSQL from my localhost.



I have a host (www.printcity24.com) with mysql db and I use this code to connect to mysql db :



<?php
$db_path = mysqli_connect('printcity24.com', 'myuser', 'mypass', 'mydb', '3306');
if(!$db_path) {
echo mysqli_connect_error();
}else{
echo "Connected successfully";
}

?>


when i call this code from printcity24.com every thing is OK and connect to mysql db successfully.



but i created a localhost by xampp on my computer and when i call this code i got this error :




Warning: mysqli_connect(): MySQL server has gone away in C:Program
FilesXAMPPhtdocsindex.php on line 2



Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in
C:Program FilesXAMPPhtdocsindex.php on line 2 MySQL server
has gone away






I talk to my web host admin and opened 3306 port on my host and added % to Manage Access Hosts on CPanel > remote MYSQL



but i still have problem to connection.










share|improve this question














I have a problem to connect to my webhost MYSQL from my localhost.



I have a host (www.printcity24.com) with mysql db and I use this code to connect to mysql db :



<?php
$db_path = mysqli_connect('printcity24.com', 'myuser', 'mypass', 'mydb', '3306');
if(!$db_path) {
echo mysqli_connect_error();
}else{
echo "Connected successfully";
}

?>


when i call this code from printcity24.com every thing is OK and connect to mysql db successfully.



but i created a localhost by xampp on my computer and when i call this code i got this error :




Warning: mysqli_connect(): MySQL server has gone away in C:Program
FilesXAMPPhtdocsindex.php on line 2



Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in
C:Program FilesXAMPPhtdocsindex.php on line 2 MySQL server
has gone away






I talk to my web host admin and opened 3306 port on my host and added % to Manage Access Hosts on CPanel > remote MYSQL



but i still have problem to connection.







php mysql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 15:07









S R RS R R

336




336













  • Can you use a tool such MySQL WorkBench to connect to your remote DB?

    – Cid
    Nov 20 '18 at 15:11











  • why should i use MySQL WorkBench ? does it better than xampp? i dont know how to use it.

    – S R R
    Nov 20 '18 at 15:23






  • 1





    It has nothing to do with xamp. It's a tool to manage your MySQL databases. You can use it to check if you can remotly connect to your db

    – Cid
    Nov 20 '18 at 15:25











  • To add to what Cid said, the purpose of doing so is to rule out the possibility of an issue in your PHP code, since Workbench is known to connect properly to Mysql.

    – ADyson
    Nov 20 '18 at 15:25













  • Another thing to try is explicitly adding your (public) IP address to the allowed hosts lists, rather than just %.

    – ADyson
    Nov 20 '18 at 15:26



















  • Can you use a tool such MySQL WorkBench to connect to your remote DB?

    – Cid
    Nov 20 '18 at 15:11











  • why should i use MySQL WorkBench ? does it better than xampp? i dont know how to use it.

    – S R R
    Nov 20 '18 at 15:23






  • 1





    It has nothing to do with xamp. It's a tool to manage your MySQL databases. You can use it to check if you can remotly connect to your db

    – Cid
    Nov 20 '18 at 15:25











  • To add to what Cid said, the purpose of doing so is to rule out the possibility of an issue in your PHP code, since Workbench is known to connect properly to Mysql.

    – ADyson
    Nov 20 '18 at 15:25













  • Another thing to try is explicitly adding your (public) IP address to the allowed hosts lists, rather than just %.

    – ADyson
    Nov 20 '18 at 15:26

















Can you use a tool such MySQL WorkBench to connect to your remote DB?

– Cid
Nov 20 '18 at 15:11





Can you use a tool such MySQL WorkBench to connect to your remote DB?

– Cid
Nov 20 '18 at 15:11













why should i use MySQL WorkBench ? does it better than xampp? i dont know how to use it.

– S R R
Nov 20 '18 at 15:23





why should i use MySQL WorkBench ? does it better than xampp? i dont know how to use it.

– S R R
Nov 20 '18 at 15:23




1




1





It has nothing to do with xamp. It's a tool to manage your MySQL databases. You can use it to check if you can remotly connect to your db

– Cid
Nov 20 '18 at 15:25





It has nothing to do with xamp. It's a tool to manage your MySQL databases. You can use it to check if you can remotly connect to your db

– Cid
Nov 20 '18 at 15:25













To add to what Cid said, the purpose of doing so is to rule out the possibility of an issue in your PHP code, since Workbench is known to connect properly to Mysql.

– ADyson
Nov 20 '18 at 15:25







To add to what Cid said, the purpose of doing so is to rule out the possibility of an issue in your PHP code, since Workbench is known to connect properly to Mysql.

– ADyson
Nov 20 '18 at 15:25















Another thing to try is explicitly adding your (public) IP address to the allowed hosts lists, rather than just %.

– ADyson
Nov 20 '18 at 15:26





Another thing to try is explicitly adding your (public) IP address to the allowed hosts lists, rather than just %.

– ADyson
Nov 20 '18 at 15:26












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395924%2fhow-to-connect-to-web-host-mysql-db-from-localhost%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395924%2fhow-to-connect-to-web-host-mysql-db-from-localhost%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word