By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Easy (?) PHP/MySQL question

P: n/a
I have installed PHP and MySQL using WAMP5 as my server on a Vista
machine.

I can run PHP scripts no problem.

I can create and populate MySQL tables no problem.

I cannot seem to get my PHP script to recognize any MySQL commands.

The following code fails silently, i.e. even the "die" text won't
display.
//Database Connection
$msdb = mysql_connect("127.0.0.1", "", "") or die('Could not connect
to MySQL: ' . mysql_error());
mysql_select_db("test", $msdb) or die('Could not select the database:
' . mysql_error());

What piece of info am I missing here? Is there some perl-style
include that I'm missing? Or is it some configuration parameter? Any
help appreciated.
Sep 19 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Stevebo wrote:
I have installed PHP and MySQL using WAMP5 as my server on a Vista
machine.

I can run PHP scripts no problem.

I can create and populate MySQL tables no problem.

I cannot seem to get my PHP script to recognize any MySQL commands.

The following code fails silently, i.e. even the "die" text won't
display.
//Database Connection
$msdb = mysql_connect("127.0.0.1", "", "") or die('Could not connect
to MySQL: ' . mysql_error());
mysql_select_db("test", $msdb) or die('Could not select the database:
' . mysql_error());

What piece of info am I missing here? Is there some perl-style
include that I'm missing? Or is it some configuration parameter? Any
help appreciated.
Enable all error reporting and display the errors. In your php.ini
file, ensure you have:

display_errors=on
error_reporting=E_ALL

I suspect your mysql extension isn't getting loaded.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 19 '08 #2

P: n/a

"Stevebo" <fa********@gmail.comwrote in message
news:b2**********************************@79g2000h sk.googlegroups.com...
>I have installed PHP and MySQL using WAMP5 as my server on a Vista
machine.

I can run PHP scripts no problem.

I can create and populate MySQL tables no problem.

I cannot seem to get my PHP script to recognize any MySQL commands.

The following code fails silently, i.e. even the "die" text won't
display.
//Database Connection
$msdb = mysql_connect("127.0.0.1", "", "") or die('Could not connect
to MySQL: ' . mysql_error());
mysql_select_db("test", $msdb) or die('Could not select the
database:
' . mysql_error());

What piece of info am I missing here? Is there some perl-style
include that I'm missing? Or is it some configuration parameter?
Any
help appreciated.
Can you connect to mySQL using another client?
MySQL query browser.. mySQL admin?

Turning on the error reporting (as Jerry suggested) is of course good.
You can do that from the tray icon.
While you are there, check to see if the extension for mySQL is
loaded.
Can you connect to the DB if you select "phpMyAdmin" from the tray
menu?

Richard.
Sep 19 '08 #3

P: n/a
On Sep 19, 2:20*pm, "Richard" <root@localhostwrote:
Can you connect to mySQL using another client?
MySQL query browser.. mySQL admin?
Yes. i can do so with MySQL query browser
Turning on the error reporting (as Jerry suggested) is of course good.
I did this using the WAMP Tray Icon =Config Files, but nothing
changed
While you are there, check to see if the extension for mySQL is
loaded.
The extension = php_mysql.dll in php.ini is uncommented, but it isn't
loaded either, nor does it show up in phpinfo()
Can you connect to the DB if you select "phpMyAdmin" from the tray
menu?
No, because it's trying to use http://localhost/, which for some
reason maps to http://www.localhost.com/ and gives an error that the
connection was reset (essentially a 404). If I substitute http://127.0.0.1/,
my page gets served but no database response. When I go to
http://127.0.0.1/phpMyAdmin, I receive

"Cannot load mysql extension. Please check your PHP configuration. -
Documentation"

The hosts file has hundreds of entries for localhost, most of them put
in by Spybot. I tried to edit the hosts file, but it's read-only.
when I remove that, and forcibly try to overwrite it, I still can't.

Any ideas?
Sep 19 '08 #4

P: n/a
Testing. My last post disappeared.
Sep 19 '08 #5

P: n/a
Stevebo wrote:
On Sep 19, 2:20 pm, "Richard" <root@localhostwrote:
>Can you connect to mySQL using another client?
MySQL query browser.. mySQL admin?

Yes. i can do so with MySQL query browser
>Turning on the error reporting (as Jerry suggested) is of course good.

I did this using the WAMP Tray Icon =Config Files, but nothing
changed
>While you are there, check to see if the extension for mySQL is
loaded.

The extension = php_mysql.dll in php.ini is uncommented, but it isn't
loaded either, nor does it show up in phpinfo()
>Can you connect to the DB if you select "phpMyAdmin" from the tray
menu?

No, because it's trying to use http://localhost/, which for some
reason maps to http://www.localhost.com/ and gives an error that the
connection was reset (essentially a 404). If I substitute http://127.0.0.1/,
my page gets served but no database response. When I go to
http://127.0.0.1/phpMyAdmin, I receive

"Cannot load mysql extension. Please check your PHP configuration. -
Documentation"

The hosts file has hundreds of entries for localhost, most of them put
in by Spybot. I tried to edit the hosts file, but it's read-only.
when I remove that, and forcibly try to overwrite it, I still can't.

Any ideas?
Did you stop and restart your Apache server after making changes to the
php.ini? Are you changing the correct php.ini file (see phpinfo()).

And are the MySQL client libraries in a place where php can access them,
i.e. in a directory listed in your PATH environment variable?

I've never used xampp (I do manual installs), so I don't know how it's
set up. But once you have it set up, everything works well.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 19 '08 #6

P: n/a
r0g
Stevebo wrote:
On Sep 19, 2:20 pm, "Richard" <root@localhostwrote:
>Can you connect to mySQL using another client?
MySQL query browser.. mySQL admin?
<snip>
The hosts file has hundreds of entries for localhost, most of them put
in by Spybot. I tried to edit the hosts file, but it's read-only.
when I remove that, and forcibly try to overwrite it, I still can't.

Any ideas?
Oh that's not good. Windows can only handle a finite number of hosts
file entries without throwing a hissy fit, plus you have no ide what is
in there. I'd lose search and destroy, (right-click, security, advanced,
owner) and reclaim ownership of the file and delete everything in it
except "127.0.0.1 localhost"

If XAMPP still isn't happy after that then try WAMP instead, I always
found it was the better of the two :-)

Of course, as Jerry suggests you could try the manual install. While it
takes longer it _is_ educational :-)

Roger.
Sep 21 '08 #7

P: n/a
On Sep 19, 5:41*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
php.ini? *Are you changing the correct php.ini file (see phpinfo()).
Yes Jerry, that was it! The wrong php.ini file. Strange, you would
have thought WAMP would pick the correct path, but perhaps it got
confused with an earlier installation of PHP.

Also Roger, thanks for the advice regarding the hosts file, but no
matter what I do to the file, I can't seem to unlock it, so the
problem persists. Since Jerry's advice got me up and running for the
moment, I'll re-visit the localhost thing when I get a chance. I'm
mostly just trying to do local development, not necessarily run my own
public web server.

Thanks for all your patience with and advice about my questions.
Steve
Sep 21 '08 #8

P: n/a
Stevebo wrote:
The hosts file has hundreds of entries for localhost, most of them put
in by Spybot. I tried to edit the hosts file, but it's read-only.
when I remove that, and forcibly try to overwrite it, I still can't.

Any ideas?
That's a bad idea. The hosts file was never intended to do mass
redirections. The whole file gets parsed on every net access to see if
the domain should resolve to a specific address before a DNS lookup is
made. A long hosts file can *really* bog down your net connectivity.

If you can't change the hosts file you have most likely configured
Spybot to protect it from tampering. Switch the hosts file protection
off in Spybot, then you should be able to edit it just fine.

Bye!
Sep 22 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.