/    Sign up×
Community /Pin to ProfileBookmark

MySql database

Hi all,

I have created a db in mysql local host with username and password.

For now I found a free server for 60 days to run my website

The problem I have is how to give the connection string from local host to the current free server domain.

The website is in php.

Pls help

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 15.2016 — It is not clear to me what you are trying to do with regard to the free server, and what that has to do with connecting to it from local host (does that mean from your own personal computer?).
Copy linkTweet thisAlerts:
@RuchithauthorFeb 15.2016 — i was sleepy, sorry. what i am saying is i got this free web server and i uploaded my db and the php files. when trying to run it its giving a lot of errors. specially with the connection string.

i have defined as localhost. now i need to change and i dont know what to change it to
Copy linkTweet thisAlerts:
@NogDogFeb 15.2016 — You may have to find that out from the hosting company. Somewhere on their control panel for your site there, they should have info about the host name (and possibly port number) you should use to connect to the DB server.
Copy linkTweet thisAlerts:
@RuchithauthorFeb 16.2016 — thank you.
Copy linkTweet thisAlerts:
@ginerjmFeb 20.2016 — Has your problem been solved yet? I ask only because I'm thinking that you might be trying to get an answer from a recalcitrant hosting company.

Here is how my code does it ( I use pdo)
[code=php]
$pdo = new PDO($host,$uid,$pswd,$db_options);
[/code]


where $host is the string:
[code=php]
$host="mysql:host=localhost;dbname=$sc_dbname;charset=utf8";
[/code]

$uid and $pswd are what you have setup when you created the database that you are trying to connect to. $db_options are defaulted to the common settings:
[code=php]
$db_options = array(PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
[/code]


This code is part of a std. db connect function that I use all the time where I pass in the desired dbname as an argument of the function header.

Hope this helps if you haven't already solved it.
×

Success!

Help @Ruchith spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...