Page 1 of 1

Cannot connect to mysql

Posted: Wed Feb 26, 2003 4:59 pm
by matecocido
Sorry, Im absolutly newbbie with php and mysql. I read a lot of tutorials, manuals, readmes and etc. I took the code from the books but cannot make them work. I have a database created with some data in some tables. I can connect with the client mysql this way:

#mysql -u root -pmy_secret_password

that's ok.

I also created another user called php:

#mysql -u root -pmy_other_password

No problem with that.

But from within php:

<?
function cnx()
{
$host='localhost';
$usr='php';
$passwd='my_other_password'
$bd='regofer';

$idconex=mysql_connect($host,$usr,$paswd);
if(!$idconex)
{
echo "Error connecting server $host with user name $usr";
exit();
}
if (!mysql_select_db($bd,$idconex))
{
echo "Error opening data base $bd";
exit();
}
return $idconex;
}

$idconex=cnx();
?>

(I tried with other usr/password, always the same)

Warning: Can't connect to local MySQL server trhough socket '/var/lib/mysql.sock' (111) in /usr/local/apache/htdocs/phpdocs/cnx.php on line 10

followed by my own error message.

I wander if anyone can help me. Thanks in advance.

Posted: Fri Feb 28, 2003 11:29 pm
by Jade
What version of mysql are you using? It looks like your mysql is looking for a file that's not there, or is misplaced. Try actually looking for the files it says it's having a problem with to see if they are even there.

Just a suggestion.

Posted: Sun Mar 02, 2003 11:27 am
by matecocido
:D

Thanks for answering.
I got it working re installing the whole thing: apache + php, this time with the option that uses mysql functions to connect and not the built in functions of php.