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

mysql_connect not doing anything at all

P: 3
Hi there,

I wasn't sure where to put this question, since it deals with both PHP and MySQL. I apologize if this is not the correct forum for this.

I am working with a simple PHP application using MySQL at the data layer.

This is on a Windows XP machine, using IIS 6.0, MySQL 5.0, PHP 5.

The problem I am having is that a call to mysql_connect is not working, it is not doing anything at all. I'm not getting any error messages, or warnings, or a whistle, or whatever. It just does nothing at all.

This is the script:

[PHP]<?php

$dbConn = mysql_connect('127.0.0.1', 'root', 'thepassword') or die('Could not connect: ' . mysql_error());

echo "HURRAY! mysql_connect works!<br>"; // this line never gets displayed on the page

if (!$dbConn)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mydb", $dbConn);

$sql="SELECT * FROM levels";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>levelname</th>
<th>mingamesplayed</th>
<th>mingameswon</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['levelname'] . "</td>";
echo "<td>" . $row['mingamesplayed'] . "</td>";
echo "<td>" . $row['mingameswon'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($dbConn);
?>[/PHP]

I put the line that says [PHP]echo "HURRAY! mysql_connect works!<br>";[/PHP] as a reachmark; however, it never gets displayed, and I am not getting the data requested. All I get is a blank page. I even put a wrong host, username and password to provoke an error, and I don't EVEN get an error.

MySQL is working. I have created, populated and retrieved data using the tools provided by MySQL. I have created other PHP pages --not using MySQL calls-- and they work just fine.

I have tried whatever I have read throughout the internet with not success. I have checked the php.ini file for the extensions and extensions_dir, and the place where the libmysql.dll and the php_mysqli.dll should be, etc, etc, etc. But I get nothing, nothing at all.

I think here's all the info, but if you need something else to help me out, let me know to give you that extra info. You can ask me anything, even if I have tried it, so just in case whatever I have tried I have done it incorrectly.

Please help, and thanks in advance.

C
Feb 20 '08 #1
Share this Question
Share on Google+
7 Replies


dlite922
Expert 100+
P: 1,584
Do you have error reporting sign.

When you get a blank page, that's usually a telltale sign that a fatal error has occured and error reporting is not on.

Check your php.ini file to turn these on, test it by a new PHP file and try to make an error. forget a { or a semicolon. It should warn you.
Feb 20 '08 #2

P: 3
Nope, nada, zilch, nothing....

I have the php.ini entries set up for error logging and nothing gets logged.

What else should I check?
Feb 21 '08 #3

P: 5
Hey!

Try This:


[PHP]
<?php

$dbConn = mysql_pconnect('127.0.0.1', 'root', 'thepassword');
if (!$dbConn){ die('Could not connect: ' . mysql_error()); }

echo "HURRAY! mysql_pconnect works!<br>"; // this line should be displayed now

mysql_select_db("mydb", $dbConn);

$sql="SELECT * FROM levels";

$result = mysql_query($sql);
if(!$result){ die mysql_error(); }

echo "
<table border='1'>
<tr>
<th>levelname</th>
<th>mingamesplayed</th>
<th>mingameswon</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['levelname'] . "</td>";
echo "<td>" . $row['mingamesplayed'] . "</td>";
echo "<td>" . $row['mingameswon'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($dbConn);
?>
[/PHP]
Feb 21 '08 #4

TheServant
Expert 100+
P: 1,168
Instead of:
<?php

$dbConn = mysql_connect('127.0.0.1', 'root', 'thepassword') or die('Could not connect: ' . mysql_error());

echo "HURRAY! mysql_connect works!<br>"; // this line never gets displayed on the page

if (!$dbConn)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mydb", $dbConn);

$sql="SELECT * FROM levels";

..
Try:
[PHP]
mysql_connect("127.0.0.1", "root", "thepassword") or die('Could not connect to MySQL: ' . mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("mydb") or die('Could not connect to Database: ' . mysql_error());
echo "Connected to Database";

$result = mysql_query("SELECT * FROM levels") or die('Could not connect to Table: ' . mysql_error());

[/PHP]

You were dying twice for some reason (line 3 and 9 or your code) and even though it might work, I am not familiar with the way you wrote it with regards to how you use mysql_select_db and a few others. Then again, I am very new, so maybe everything I have said is a waste of time. If so, let me know and I will shut up!
Feb 21 '08 #5

P: 5
or you could just try the one i posted :P it has to work :D lol
Feb 21 '08 #6

P: 3
Many thanks to all who replied.

All suggestions are good, but they are all the same. In fact, my lines of code were taken from a working example.

Anyway, I am embarassed to say that it now works and it only required a good old reboot of my machine!! :S

Although one thing that hint me about doing a reboot was the php.exe shell. I invoked my php page through the shell and it gave me the error messages that were not showing up on the browser. So I corrected them and rebooted.

TA-DA!

I leave this information for everyone, so nobody else goes through this embarassment... :-(

Again, thanks to all who posted!
Feb 21 '08 #7

Markus
Expert 5K+
P: 6,050
or you could just try the one i posted :P it has to work :D lol
More than one suggestions are welcome.
Feb 21 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.