/    Sign up×
Community /Pin to ProfileBookmark

unable to connect to mysql from the command line

Hi people

I have a php application which successfully connects to mysql and interacts with the database.
I am using apache as my web server.

I would like to invoke my code from the command shell, using php.exe like so:
c:phpphp.exe c:script.php

in script.php I am using mysql_connect to connect to the database.
I get the following error:
Access denied for user ‘root’@’localhost’ (using password: YES)

Note that the same script is working perfectly when invoked via the web server…

what do I need to do in order to make my script work from the command line?

regards

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chazzyOct 22.2006 — can you show us your code?
Copy linkTweet thisAlerts:
@jasongrauthorOct 23.2006 — I found the problem.

the fact that the code was involed from the command line, caused some of the global parameters in $_SERVER not to be initialized properly, and that caused me to attempt to connect to the database using the wrong password.
×

Success!

Help @jasongr 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...