/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] problems with connecting to mysql

Hi,

I’ve got the following two pure php files:

config.php:

[code]
<?php
$dbhost = ‘localhost’;
$dbuser = ‘root’;
$dbpass = ‘password’;
$dbname = ‘cats’;
?>
[/code]

opendb.php:

[code]
<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (“Error connecting to mysql”);
mysql_select_db($dbname) or die (‘Could not connect to database’);
?>
[/code]

I also have another page called index.php. It contains a bunch of html, and then:

[code]
<?php
include “config.php”;
include “opendb.php”;

further php commands;
?>
[/code]

Including opendb makes the entire webpage show up blank in my browser. If anybody has any ideas why this is, I would be very grateful. ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Aug 10.2010 — Try turning on error reporting

[code=php]
error_reporting(E_ALL);
ini_set('display_errors', '1');
[/code]


Also, what happens if you place the values directly into the mysql_connect() and mysql_select_db() functions.
Copy linkTweet thisAlerts:
@apolishchauthorAug 10.2010 — I've turned on error reporting as you suggested above, and plugged the values in directly. The result is the same, a blank html page :/

Funnily enough, no error message comes up. The database is set up correctly, as I have earlier on locally populated it using those same parameters by using a java program, and if i comment out the line "include "opendb"" The webpage displays the contents it should be displaying...

Any help/ideas would be greatly appreciated :/
Copy linkTweet thisAlerts:
@skywalker2208Aug 10.2010 — How did you deduce the problem is opendb.php? I would suggest putting and echo statement afterward with an exit statement to see if it really is the problem. Then you can move the two statement around to figure out where the problem is.
Copy linkTweet thisAlerts:
@apolishchauthorAug 11.2010 — Hey,

I deduced that it was opendb by commenting out lines until the page loaded. Also, I apologize, a fairly lengthy error message was actually produced after some time, I just didn't notice it before posting yesterday. The entirety of the error message was:

<i>
</i>Warning: mysql_connect(): It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning,
you most likely misspelled the timezone identifier.
We selected 'Europe/London' for '1.0/DST'
instead in C:Program FilesApache Software FoundationApache2.2htdocssearch.php
on line 60 Warning: mysql_connect(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)
in C:Program FilesApache Software FoundationApache2.2htdocssearch.php on line 60 Warning: mysql_connect():
It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning, you most likely
misspelled the timezone identifier. We selected 'Europe/London' for '1.0/DST'
instead in C:Program FilesApache Software FoundationApache2.2htdocssearch.php on line 60 Warning:
mysql_connect(): A connection attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has failed to respond. in
C:Program FilesApache Software FoundationApache2.2htdocssearch.php on line 60 Warning: main():
It is not safe to rely on the system's timezone settings. You are *required*
to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning,
you most likely misspelled the timezone identifier. We selected 'Europe/London'
for '1.0/DST' instead in C:Program FilesApache Software FoundationApache2.2htdocssearch.php on
line 60 Fatal error: Maximum execution time of 30 seconds exceeded in C:Program FilesApache Software FoundationApache2.2htdocssearch.php on line 60


I have fixed this and the page now loads. The solution (I'm not quite sure why it solved it but anyways) is changind the declaration:

<i>
</i>$dbhost = "localhost";

with
<i>
</i>$dbhost = "127.0.0.1:3306";


Thank you very much for your time though ?
×

Success!

Help @apolishch 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 5.9,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...