473,573 Members | 3,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems Connecting To MySQL

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
6 1793
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*******@attgl obal.net
=============== ===
Aug 2 '05 #2
MBS
Jerry Stuckle <js*******@attg lobal.net> wrote in
news:36******** ************@co mcast.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('S ELECT 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_arr ay($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
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
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('S ELECT 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_arr ay($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
MBS
paul <pa**@not.net > wrote in news:A7******** ************@sp eakeasy.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('S ELECT 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_arr ay($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('SE LECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_arr ay($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
MBS wrote:
Jerry Stuckle <js*******@attg lobal.net> wrote in
news:36******** ************@co mcast.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('S ELECT 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_arr ay($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_reportin g=E_ALL)
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 2 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2044
by: maddunr | last post by:
Hi, I just installed PHP 4.3.9, MySQL 4.0.2 and PHPMyAdmin 2.6.0-pl3 on our intranet server (Win2k3 running IIS). I also have a similar setup on my local machine (http://localhost/phpmyadmin). Everything seems normal when I work on the server machine (also known as web-nt with IP xxx.xxx.xx.xx), but when I try connecting to the MySQL...
4
1786
by: CodeImp | last post by:
A simple app I quickly wrote to try getting info from a database. Here is the first part of its code. The rest of the code is irellevant. using System; using System.Data; using System.Data.SqlClient; using System.Threading; namespace TestSQL { class Class1
3
4349
by: Mike | last post by:
I have transferred the data from Access to MySQL using MySQL's tool. The transfer worked great and saved me a lot of time (thanks MySQL). Now I'm trying to get the Access database, or a new access database, to talk across ODBC and see the data. I created the DSN through the control panel and it works without error. How do I setup Access...
15
2936
by: John Nagle | last post by:
I've been installing Python and its supporting packages on a dedicated server with Fedora Core 6 for about a day now. This is a standard dedicated rackmount server in a colocation facility, controlled via Plesk control panel, and turned over to me with Fedora Core 6 in an empty state. This is the standard way you get a server in a colo...
0
1788
by: ELINTPimp | last post by:
Hello folks, Having a bit of trouble getting PDO to connect to my remote MySQL database... PHP: 5.2.1, w/ php_mysql, php_pdo, php_pdo_mysql; error reporting is on, ERROR_STRICT (development server) OS: Windows 2003 R2 w/ SP2 Web Server: IIS 6, PHP installed as ISAPI MySQL: 3.23.54 on remote Solaris 9 9/04
3
1204
by: thamood | last post by:
hi guys i have a problem with the output of my script... 1- i created a simple MySQL Database using phpMyAdmin and the encoding was "utf8_general_ci" 2- i addes a few rows in a table in ARABIC 3- the names shows well in phpMyAdmin the problem is when i want to display them in PHP they all come out in "???????" i tried using english names...
8
4721
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql with java in eclipse environment. Coding Part: import java.sql.Connection; import java.sql.DriverManager; public class MysqlConnect {
5
1564
by: bodhiSoma | last post by:
Hi all. Can't seem to get PHP to play nice with MySQL. First I logged into MySQL, created the db, switched to it and then granted (what I thought were) correct privileges: -------- Macintosh-7:~ jason$ /usr/local/mysql/bin/mysql -u root mysqlcreate database wes;
2
2625
by: Alfons Nonell-Canals | last post by:
Hello, I've developed a program using python that have to connect to a mysql server several times. In a local machine (running the program in the same machine where the mysql server is) I have no problems. I can run several instances of the program at the same time with no problem. Them problem arrives when I try to distribute the tasks...
0
7707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8086
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6432
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1325
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1048
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.