LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Accessing MySQL from a PHP script (locally) (https://www.linuxquestions.org/questions/linux-software-2/accessing-mysql-from-a-php-script-locally-119329/)

lowpro2k3 11-23-2003 08:28 PM

Accessing MySQL from a PHP script (locally)
 
I just installed MySQL, Apache and PHP the way they installed it from "PHP - Fast and Easy Web Development" (kind of, RPM's didnt seem to work, so installing from source is what worked), i.e., For them to all work with each other (mostly just PHP needed additional parameters for configuration). MySQL works on its own, and I can access and parse my normal PHP scripts through Apache, but I used this code to try and access my MySQL database and it gave the error below:

PHP Code:

<?
$connection 
mysql_connect("localhost""root""mypassword") or die(mysql_error());

if (
$connection) {
    
$msg "it worked";
}

?>

<html>
<head>
<title>MySQL Connection</title>
</head>
<body>

<? echo "$msg"?>

</body>
</html>

I get the following error message, and I'm not too sure what to make of it: Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /usr/local/apache_1.3.29/htdocs/phpsql.php on line 2
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


Hopefully some people have gone through this before and can help me out a little here, it would be much appreciated, I'm sitting here scratching my head...

Thanks alot!


:scratch:

ugenn 11-23-2003 08:47 PM

either one or more of the following...

1. MySQL daemon isn't running.
2. it's working but configured to listen on a non-default port
3. Password is wrong (did u initialise the database using mysql_install_db)?

Doomhammer 11-23-2003 09:50 PM

have you setup the php.confing.inc file accordingly??


All times are GMT -5. The time now is 09:03 PM.