LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2004, 11:37 PM   #1
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Rep: Reputation: 15
mysql_connect failure


I am trying to get a local connection to an my installation of mysql via PHP without any success. I would like to post some error codes, however I am not receiving any. Simply fails.

the php code is the standard:
<?php
$db_host="localhost";
$db_username="username";
$db_password="password";
mysql_connect($db_host, $db_username, $db_password) or die ('Connection failed');
?>

I have tried using double quotes and actual values instead of variables with the same results. I have also inserted: $db_host="localhost:3306";
and added the: mysql_error() ex.
mysql_connect($db_host, $db_username, $db_password) or die("Connection faild") . mysql_error());

all without success.

I can log on using the clients so I know that my db credentials are correct.

Running the following:
RH FC2 (2.6.5-1.358)
PHP 4.3.8
Apache 2.0
MySQL 4.0.20-standard

Any input would be greatly appreciated.

Last edited by anthony1101; 10-27-2004 at 01:35 AM.
 
Old 10-27-2004, 01:03 AM   #2
dugas
Member
 
Registered: Jul 2004
Location: louisiana
Distribution: fedora 4/kubuntu
Posts: 116

Rep: Reputation: 15
put this function inside your .php file
function db_connect($dbhost, $dbname, $dbuser, $dbpass) {
/* connect to the database $dbname on $dbhost with the user/password pair
* $dbuser and $dbpass. */

global $DB_DIE_ON_FAIL, $DB_DEBUG;

if (! $dbh = mysql_pconnect($dbhost, $dbuser, $dbpass)) {
if ($DB_DEBUG) {
echo "<h2>Can't connect to $dbhost as $dbuser</h2>";
echo "<p><b>MySQL Error</b>: ", mysql_error();
} else {
echo "<h2>Database error encountered</h2>";
}

if ($DB_DIE_ON_FAIL) {
echo "<p>This script cannot continue, terminating.";
die();
}
}

if (! mysql_select_db($dbname)) {
if ($DB_DEBUG) {
echo "<h2>Can't select database $dbname</h2>";
echo "<p><b>MySQL Error</b>: ", mysql_error();
} else {
echo "<h2>Database error encountered</h2>";
}

if ($DB_DIE_ON_FAIL) {
echo "<p>This script cannot continue, terminating.";
die();
}
}

return $dbh;
}
Then assign your variables
$dbhost='localhost'
$dbname='database_name'
$dbpass='password'
$dbuser='username'
Then call the function with
db_connect('$dbhost','$dbname','$dbuser','$dbpass')
Post what is says when you call this script.
Let me know if you need some help.
 
Old 10-27-2004, 01:52 AM   #3
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
I couldn't sleep and when I got up I was happy to see some code to work with. Sadly, it did not do the trick. I still am getting NO ERROR codes. This is really VERY frustrating to not even really know where the code is failing. With some control lines inserted, it seems that PHP or MySQL is balking at the mysql_connect statement, but for the life of me I cannot figure out what it dislikes or even if it is functional or even what search terms to use to locate and answer.

I know the scripts work, because I have used them on a remote machine, but I need them to be working locally. If you have any more insight, please let me know. Much Thanks!
 
Old 10-27-2004, 03:54 AM   #4
JurajPsycho
Member
 
Registered: Sep 2004
Distribution: Debian, kernel 2.6.10
Posts: 50

Rep: Reputation: 15
hmm

did you check, wheter your error reporting isn't turned off?
J.
 
Old 10-27-2004, 09:42 AM   #5
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
No...where do I check that? I would have expected to get an SQL error dumped to the screen with mysql_error()
 
Old 10-27-2004, 11:39 AM   #6
dugas
Member
 
Registered: Jul 2004
Location: louisiana
Distribution: fedora 4/kubuntu
Posts: 116

Rep: Reputation: 15
You check it in your php.ini file
 
Old 10-27-2004, 01:16 PM   #7
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
Ok..I have enabled display_error = On (must perform a restart of httpd)

now I have something to work with:
Fatal error: Call to undefined function: mysql_connect() in /var/www/html/db_open.php on line 18

Looking into it now.

Last edited by anthony1101; 10-27-2004 at 01:22 PM.
 
Old 10-27-2004, 02:40 PM   #8
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
It looks like I did not have the sql libraries installed, even though all the documentation that I can find is that php 4 and greater included them.

Since I had to install them I went ahead and removed 4.0.20 and have installed 5.0.2.

I'll post an update in a few minutes after php finishes compiling.
 
Old 10-27-2004, 02:49 PM   #9
dugas
Member
 
Registered: Jul 2004
Location: louisiana
Distribution: fedora 4/kubuntu
Posts: 116

Rep: Reputation: 15
are you for sure compiling php with mysql enabled option?
 
Old 10-27-2004, 03:02 PM   #10
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
yeah...I complied php
./configure --with-mysql=/usr/bin/myssql

I didn't have the library files so I had to go and retrieve those...and it complied fine. However now PHP is not working with apache.

I'm downloading the manual for PHP now...

Reading through the docs I am recompiling with:
./configure --with-mysql

Last edited by anthony1101; 10-27-2004 at 03:22 PM.
 
Old 10-28-2004, 08:14 PM   #11
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
OK, since php was installed as an RPM package and requires custom configuration I decided to go ahead and install PHP5. This of course required a recompile of apache since it was configured to use php4. I had a little trouble getting apache to comiple correctly since I didn't have some of the binary files. (Required a make clean)

At any rate I finally got apache installed and php5 installed and apache tells me that PHP is configured, however my PHP files are showing up as plain text.

I have already configured httpd.conf to include:
LoadModule php5_module modules/libphp5.so

and

AddType application/x-httpd-php .php .phtml

Did an apachectl stop and subsequent start.

The PHP files are now loading a plain text. Any suggestions?
 
Old 10-29-2004, 11:58 AM   #12
anthony1101
Member
 
Registered: Aug 2004
Location: Texas
Distribution: FC3
Posts: 59

Original Poster
Rep: Reputation: 15
SUCCESS!!!

I found that I was editing the old httpd.conf file. Once I inserted the correct lines and restarted Apache it is working.

LoadModule php5_module modules/libphp5.so
was already inserted, however I found that may references to the AddType were not quite right.
The correct command was:
AddType application/x-httpd-php .php .phtml
AddType application/x-http-php-source .phps .phtmls

Hopefully this will help someone lighting their LAMP server.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php mysql_connect error compu73rg33k Linux - Software 11 04-02-2005 05:37 AM
Call to undefined function: mysql_connect() SocialEngineer Linux - Software 2 11-16-2004 02:24 PM
mysql_connect problem w/apache+php CodeCrush Linux - Software 0 05-24-2004 08:35 AM
undefined function: mysql_connect Greenman Programming 8 12-27-2003 05:35 AM
Redhat PHP 4.2 Problem, no mysql_connect() nehalem Linux - Software 1 11-20-2003 12:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration