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

Problems Connecting To MySQL

P: n/a
MBS
Yeah, read the previous posts...I did that. None answer my question.

I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago
on WinXP SP2. My goal is to learn to use these programs.

I cannot, absolutely cannot connect to MySQL using PHP. I've tried
everything possible including the mysqli functions.

I have no idea what is wrong. I don't get any error messages at all. It's
almost as if PHP stops processing the php file in mid stream.

PHP is installed properly (I followed the installation instructions to the
letter). Simple php files process OK. MySQL is installed fine--I've
loaded data from an Access table and have been querying it fine using the
MySQL Query Browser. But I cannot connect to MySQL using PHP!

Is there anyone out there that can help me?

I am thinking that someone could create a simple DB with one table in it
with a little bit of text in one of the fields (as a test), then write some
PHP code that they KNOW works. Then I'll set up a DB the same and run that
PHP code and see if it works on my system.

Shouldn't take someone more than two or three minutes to do this. If they
are willing to help...

I've been working on this for about 3 hours now to no avail. I'm about
ready to give up on this open source stuff. But I really do want to learn
this. I just need help getting over this one little hurdle.

Thanks.

Aug 2 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
MBS wrote:
Yeah, read the previous posts...I did that. None answer my question.

I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago
on WinXP SP2. My goal is to learn to use these programs.

I cannot, absolutely cannot connect to MySQL using PHP. I've tried
everything possible including the mysqli functions.

I have no idea what is wrong. I don't get any error messages at all. It's
almost as if PHP stops processing the php file in mid stream.

PHP is installed properly (I followed the installation instructions to the
letter). Simple php files process OK. MySQL is installed fine--I've
loaded data from an Access table and have been querying it fine using the
MySQL Query Browser. But I cannot connect to MySQL using PHP!

Is there anyone out there that can help me?

I am thinking that someone could create a simple DB with one table in it
with a little bit of text in one of the fields (as a test), then write some
PHP code that they KNOW works. Then I'll set up a DB the same and run that
PHP code and see if it works on my system.

Shouldn't take someone more than two or three minutes to do this. If they
are willing to help...

I've been working on this for about 3 hours now to no avail. I'm about
ready to give up on this open source stuff. But I really do want to learn
this. I just need help getting over this one little hurdle.

Thanks.


How about showing us the code you're using?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 2 '05 #2

P: n/a
MBS
Jerry Stuckle <js*******@attglobal.net> wrote in
news:36********************@comcast.com:
MBS wrote:
Yeah, read the previous posts...I did that. None answer my question.

I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few
days ago on WinXP SP2. My goal is to learn to use these programs.

I cannot, absolutely cannot connect to MySQL using PHP. I've tried
everything possible including the mysqli functions.

I have no idea what is wrong. I don't get any error messages at all.
It's almost as if PHP stops processing the php file in mid stream.

PHP is installed properly (I followed the installation instructions
to the letter). Simple php files process OK. MySQL is installed
fine--I've loaded data from an Access table and have been querying it
fine using the MySQL Query Browser. But I cannot connect to MySQL
using PHP!

Is there anyone out there that can help me?

I am thinking that someone could create a simple DB with one table in
it with a little bit of text in one of the fields (as a test), then
write some PHP code that they KNOW works. Then I'll set up a DB the
same and run that PHP code and see if it works on my system.

Shouldn't take someone more than two or three minutes to do this. If
they are willing to help...

I've been working on this for about 3 hours now to no avail. I'm
about ready to give up on this open source stuff. But I really do
want to learn this. I just need help getting over this one little
hurdle.

Thanks.


How about showing us the code you're using?


OK. But it's from a book and copyrighted. That's why I didn't provide it
originally. But here goes:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our List of Jokes</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
?>
<p>Here are all the jokes in our database:</p>
<blockquote>
<?php
// Request the text of all the jokes

$result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>
</blockquote>
</body>
</html>

Hope that helps.

The problem is that the HTML produced stops after the <body> tag. Also,
looking at my MySQL log, I do not see that any connection was made.

I also tried mysqli_connect as well. That didn't work, either.

Thanks.

Aug 2 '05 #3

P: n/a
MBS wrote:
Hope that helps.

The problem is that the HTML produced stops after the <body> tag. Also,
looking at my MySQL log, I do not see that any connection was made.


Try using:

$dbcnx = mysql_connect('localhost', 'root', 'mypasswd') or die
(mysql_error());

....and see if it prints out anything.
Aug 2 '05 #4

P: n/a
MBS wrote:
....
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
} ....
$result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
The problem is that the HTML produced stops after the <body> tag.

But you aren't getting any results from those error trapping thingies?
Try putting print statements in there along the way to debug what's
happening at each step.

In front of:

if (!$dbcnx) {

put:

print "$dbcnx; //debug

etc.

Also,
looking at my MySQL log, I do not see that any connection was made.

I also tried mysqli_connect as well. That didn't work, either.

Thanks.

Aug 2 '05 #5

P: n/a
MBS
paul <pa**@not.net> wrote in news:A7********************@speakeasy.net:
MBS wrote:
...
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}

...

$result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';


The problem is that the HTML produced stops after the <body> tag.

But you aren't getting any results from those error trapping thingies?
Try putting print statements in there along the way to debug what's
happening at each step.

In front of:

if (!$dbcnx) {

put:

print "$dbcnx; //debug

etc.

Also,
looking at my MySQL log, I do not see that any connection was made.

I also tried mysqli_connect as well. That didn't work, either.

Thanks.


Sorry. I removed the error-suppressing "@" in the php file on the
server. I forgot to remove them when copying and pasting the code from
the book

I GOT IT TO WORK!!!

The example from the book did not work. But, I found another connection
example and tweaked it. This works:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');

$dbname = 'ijdb';
mysql_select_db($dbname);

$result = mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}

?>

Thank goodness! I was getting so frustrated. Well, I have a new toy to
play with. Thanks for everyone who took the time to read and/or reply to
my plea for help.
Aug 2 '05 #6

P: n/a
MBS wrote:
Jerry Stuckle <js*******@attglobal.net> wrote in
news:36********************@comcast.com:

MBS wrote:
Yeah, read the previous posts...I did that. None answer my question.

I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few
days ago on WinXP SP2. My goal is to learn to use these programs.

I cannot, absolutely cannot connect to MySQL using PHP. I've tried
everything possible including the mysqli functions.

I have no idea what is wrong. I don't get any error messages at all.
It's almost as if PHP stops processing the php file in mid stream.

PHP is installed properly (I followed the installation instructions
to the letter). Simple php files process OK. MySQL is installed
fine--I've loaded data from an Access table and have been querying it
fine using the MySQL Query Browser. But I cannot connect to MySQL
using PHP!

Is there anyone out there that can help me?

I am thinking that someone could create a simple DB with one table in
it with a little bit of text in one of the fields (as a test), then
write some PHP code that they KNOW works. Then I'll set up a DB the
same and run that PHP code and see if it works on my system.

Shouldn't take someone more than two or three minutes to do this. If
they are willing to help...

I've been working on this for about 3 hours now to no avail. I'm
about ready to give up on this open source stuff. But I really do
want to learn this. I just need help getting over this one little
hurdle.

Thanks.


How about showing us the code you're using?

OK. But it's from a book and copyrighted. That's why I didn't provide it
originally. But here goes:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our List of Jokes</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
?>
<p>Here are all the jokes in our database:</p>
<blockquote>
<?php
// Request the text of all the jokes

$result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>
</blockquote>
</body>
</html>

Hope that helps.

The problem is that the HTML produced stops after the <body> tag. Also,
looking at my MySQL log, I do not see that any connection was made.

I also tried mysqli_connect as well. That didn't work, either.

Thanks.


Is your database on your local machine? Is the MySQL user id 'root' and the
password 'password'?

And take the '@'s off the beginning of your function calls. They may be hiding
errors.

Try turning on all errors in your PHP.INI file (error_reporting=E_ALL)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 2 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.