LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-16-2010, 05:55 PM   #1
elliot01
Member
 
Registered: Jun 2009
Location: UK
Distribution: CentOS / RedHat
Posts: 89

Rep: Reputation: 16
Question Can't get PHP to connect to MySQL on same server


Hi all,

I've just decided to jump in and learn some PHP and MySQL stuff, by creating a dbase on our intranet server (CentOS5.4/Apache/PHP).

Everything seemed to go great with the MySQL dbase creation - I can even successfully connect to the dbase via ODBC on a Windows box (but there's no data in there yet).

My next step was to create a PHP form to gather info from intranet users, which would be submitted to and stored in the MySQL dbase.

I have tried following various basic tutorials online but I have started to struggle. If I run even the most simple of PHP connection on the server, I just get a blank page (i.e.: no 'connected' or 'failure to connect' message).

For instance:

<?php
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>

If I run this, I get a blank page.

How can I start to troubleshoot this? As mentioned I felt quite confident that MySQL was working due to success with ODBC, and the server already serves html/PHP services/pages as it's an existing intranet server.

What can I check?

Thanks in advance!
 
Old 02-16-2010, 06:02 PM   #2
elliot01
Member
 
Registered: Jun 2009
Location: UK
Distribution: CentOS / RedHat
Posts: 89

Original Poster
Rep: Reputation: 16
I have just come across this in my httpd/error_log:

Code:
[Tue Feb 16 23:34:19 2010] [error] [client 10.11.22.214] PHP Fatal error:  Call to undefined function mysql_connect() in /var/www/intranet.my-domain.local/itprojects/infor/SX e/stock/testsql.php on line 2
Does this mean my PHP is broken somehow? I thought I had installed all the necessary packages from a guide earlier today. This shows what I installed/updated earlier (from /var/log/messages:

Code:
Feb 16 13:14:33 intranet yum: Updated: mysql-5.0.77-4.el5_4.1.x86_64
Feb 16 13:16:58 intranet yum: Updated: php-common-5.1.6-24.el5_4.5.x86_64
Feb 16 13:16:59 intranet yum: Updated: php-cli-5.1.6-24.el5_4.5.x86_64
Feb 16 13:17:00 intranet yum: Installed: php-pdo-5.1.6-24.el5_4.5.x86_64
Feb 16 13:17:02 intranet yum: Installed: perl-DBD-MySQL-3.0007-2.el5.x86_64
Feb 16 13:17:05 intranet yum: Installed: mysql-server-5.0.77-4.el5_4.1.x86_64
Feb 16 13:17:08 intranet yum: Updated: php-5.1.6-24.el5_4.5.x86_64
Feb 16 13:17:09 intranet yum: Installed: php-mysql-5.1.6-24.el5_4.5.x86_64
Feb 16 13:17:10 intranet yum: Updated: php-ldap-5.1.6-24.el5_4.5.x86_64
Any suggestions would be very much appreciated.

Cheers.
 
Old 02-16-2010, 06:12 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Make sure mysql.so module is loading. Look at your php.ini file.
You can verify apache/php settings via the phpinfo() function.
 
Old 02-16-2010, 06:20 PM   #4
elliot01
Member
 
Registered: Jun 2009
Location: UK
Distribution: CentOS / RedHat
Posts: 89

Original Poster
Rep: Reputation: 16
Hi michaelk,

Thanks very much for that quick reply

The error I discovered led me to http://www.somacon.com/p109.php which in turn led me to realise that I may just need to restart Apache

I have just retried the simply connection PHP file from earlier, and that is now giving feedback, so I think it may now be fixed! Woohoo!

Hopefully this will be of use to someone else suffering the same issue in the future

Cheers.
 
  


Reply



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
is there a client install for MySql so PHP can connect to MySQL Server? alar Linux - Software 8 07-03-2007 07:42 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 03:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
Can't connect to MySQL server using PHP Lars79 Linux - Newbie 3 08-05-2004 03:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:27 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