Hi, I'm using Red Hat Linux 9, and I'm trying to set up PHP & MySQL on the Apache server that comes with it. PHP also came with it. My problem is that whenever PHP encounters a MySQL command (ie mysql_query) it simply dies. No error messages, no nothing. It simply just acts as if that is the end of the file.

I tried installing the php-mysql package, but it still does not work. Any help would be appreciated.

And be nice... I'm just a little newbie 😃

    Just an update... I've been looking around on Google and places, and I ended up installing a package called MySQL-Client. Still no luck. Do I have to edit some PHP config files to tell it where to find MySQL?

      Just a few suggestions to try:

      1. make sure mysql is running. If you can log into mysql through the command line, then you should be able to do so from PHP on the same machine.

      2. if it is a recent install of PHP, turn on the error codes in the php.ini file (default for a production site is to leave them off, so that sensitive info isn't shown in the browser window)

        Thanks. For 1, I don't think that applies to me, though. I'm trying to connect to a remote MySQL server, because the server I'm setting up is a testing site for my real website. So, does MySQL have to be running even if I'm not accessing its database?

        For the second one, I turned on all error reporting. The only thing I received was a notice about using a variable not being defined, but I know what that is, and it's unrelated.

        Thanks for your ideas so far, but any more?

          I tried to run MySQL, and I got the following error:

          ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

          I looked, and /var/lib/mysql/mysql.sock doesn't even exist. The directory /var/lib/mysql doesn't even exist! I tried reinstalling the MySQL-client, but it's still the same.

            it sounds like your mysql isn't installed properly...

            when you connect, try something like this:

            if (!($connection = @ mysql_connect($host,$user,$pwd)))
            { die "couldn't connect";}else{"connected properly";}

            mysql error messages are different than php error messages, and you can trap them in the die message so they are displayed.

            But first off you should try to get into mysql from the command line... Check if it is installed (rpm -q mysql) might give you the answer, unless you compiled mysql from source. I would recommend that you download a new source rpm and install it (rpm -ivh mysqlFileName.rpm) and then see if you can get that working.

              Well, I finally got an error message from PHP:

              Fatal error: Call to undefined function: mysql_connect() in /mnt/shared/game/php.php on line 30

              However, that doesn't make me feel any better. Also, I don't have the package MySQL installed, but I do have MySQL-client. That's all I need, right? I'm only trying to connect to a separate server, not create my own MySQL server. Anyway, I reinstalled MySQL-client and I'm still getting the same message when I try to run MySQL:

              ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

                I installed MySQL-server. Now, I can access MySQL from the command line fine. But I'm still getting the function does not exist message from PHP.

                  ok, you're almost there then...

                  you have to install mysql support in php. You can do this by compiling your own source and manually adjusting the code (very little adjustment is required) or by installing an rpm, usually called php-mysql..versioninfo..rpm

                  Actually, install this:php-mysql 4.2.2 - 17

                  from here: http://www.redhat.com/swr/i386/php-mysql-4.2.2-17.i386_dl.html

                  or select the php-mysql rpm version for your currently installed php version.

                    I already had php-mysql-4.2.2-17.2.rpm installed (which is the same as my version of php), so I uninstalled and reinstalled it. Then I restarted my server, and then restarted my computer. I'm sad to say, it's still not working. Still getting the mysql_connect does not exist message.

                    Thanks for all your help so far. Any final ideas?

                      check the php.ini file and enable mysql.so

                        Sorry for being a total idiot, but - how do I do that? I looked through the file, but couldn't find anything.

                          Write a Reply...