LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-30-2008, 07:33 AM   #1
homyangcha
Member
 
Registered: Jun 2008
Posts: 31

Rep: Reputation: 15
Cannot connect to mysql database using php in Apache on Centos 5.1 OS


i have been trying to connect to mysql database from apache using php in my Centos 5.1 server for the past one week but could not. I have done all the necessary steps for the php-mysql connection still it does not display any thing, not even an error message... the phpinfo() files works fine and i can work in the mysql database form the command line and create databases but still i cannot connect... here is my script file...

<?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'db_test';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Sorry! Could not connect to the Database');
mysql_connect_db($dbname, $conn);
$sql = 'select * from tblFeedback';
$recordset = mysql_query($mysql, $conn) or die ('Somethings wrong with connection');
while($row = mysql_fetch_array($recordset))
{
echo $row('0');
}

?>

the installation of php, mysql and apache are all from the distribution package only...

the result of the following commands are as follows:
1.# rpm -qa|grep php
php-mysql-5.1.6-20.el5
php-common-5.1.6-20.el5
php-pear-1.4.9-4.el5.1
php-pdo-5.1.6-20.el5
php-5.1.6-20.el5
php-cli-5.1.6-20.el5
php-odbc-5.1.6-20.el5
php-ldap-5.1.6-20.el5

2. rpm -qa|grep mysql
libdbi-dbd-mysql-0.8.1a-1.2.2
php-mysql-5.1.6-20.el5
mod_auth_mysql-3.0.0-3.1
mysql-connector-odbc-3.51.12-2.2
mysql-server-5.0.45-7.el5
mysql-5.0.45-7.el5
mysql-devel-5.0.45-7.el5

3. rpm -qa|grep httpd
httpd-manual-2.2.3-11.el5_1.centos.3
system-config-httpd-1.3.3.3-1.el5
httpd-2.2.3-11.el5_1.centos.3


Please help? Am i missing something? I am quite new to linux.
 
Old 06-30-2008, 08:18 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Maybe you should say if you get an error message somewhere (which might indeed indicate that you can not connect). Some things I see:

1) mysql_connect_db is not a PHP function (mysql_select_db however is)
2) check the return value of mysql_connect_db
3) check the error of the mysql_connect with more detail (see example here)
4) check the apache error logs (it mights say that there's an unknown function mysql_connect_db)
 
  


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
Trying to get PHP to connect to a MySQL Database bassplayer69 Programming 16 03-13-2008 09:27 PM
Centos 5, Apache, php, mysql Anauj0101 Linux - Server 5 02-26-2008 10:39 PM
Where are the database files for mysql in Centos 5? Anauj0101 Linux - Server 5 02-23-2008 05:39 PM
Apache/PHP not talking to mysql database BorgAssimilator Linux - Software 1 11-11-2005 03:12 AM
cannot connect to mysql database from php rocordial Linux - Software 2 08-21-2005 02:05 PM


All times are GMT -5. The time now is 06:32 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration