|
Home > Archive > alt.os.linux > October 2002 > php/msql help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Trojan 2002-10-04, 4:25 am |
| i'm trying to connect to a mysql database via a php script but here's the
trouble i run into:
Warning: Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) in /usr/local/apache/htdocs/ action.php on line 7
Warning: MySQL Connection Failed: Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2) in /usr/
local/apache/htdocs/action.php on line 7
Could not connect MySQL
here's my script:
<?php
$location = "localhost";
$username = "xxx";
$password = "xxx";
$database = "test2";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$con
n) or die ("Could not open database");
?>
can anyone help?
| |
| Johnny Ljunggren 2002-10-04, 6:25 am |
| Trojan wrote this:
> i'm trying to connect to a mysql database via a php script but here's the
> trouble i run into:
> Warning: Can't connect to local MySQL server through socket
> '/tmp/mysql.sock' (2) in /usr/local/apache/htdocs/ action.php on line 7
<snip>
Can you connect through the commandline? ie
mysql -uxxx -pxxx test2
--
Johnny Ljunggren, Priv: Bærefjellvn 15, 3160 STOKKE
Tlf: 918 50 411, ICQ: 50630605
| |
| Sybren 2002-10-04, 9:25 am |
| Johnny Ljunggren wrote:
> Can you connect through the commandline? ie
> mysql -uxxx -pxxx test2
If that works, try
# mysql -u xxx -pxxx -h localhost test2
That will use the network (loopback) device instead of UNIX sockets. PHP
uses the network as well for connecting to MySQL. If this doesn't work, but
the command Johnny gave you does, you have to grant more permissions to
user xxx
# mysql -u root -pxxxx
# grant insert,select,delete,update on test2.* to xxx@localhost identified
by 'xxx';
# flush privileges;
That should fix things.
Sybren
| |
| Giannis Georgalis 2002-10-04, 2:25 pm |
| Trojan <trojan@hotmail.com> writes:
> i'm trying to connect to a mysql database via a php script but here's the
> trouble i run into:
> Warning: Can't connect to local MySQL server through socket
> '/tmp/mysql.sock' (2) in /usr/local/apache/htdocs/ action.php on line 7
>
> Warning: MySQL Connection Failed: Can't connect to local MySQL server
> through socket '/tmp/mysql.sock' (2) in /usr/
> local/apache/htdocs/action.php on line 7
> Could not connect MySQL
I will assume that you are running mysqld ...
Then your problem is that php functions try to find the mysql socket
in /tmp ...and obviously mysql.sock is somewhere else (probably in
$MYSQL_INSTALL_PREFIX/var/run/). So you should either tell php where
to find mysql.sock (in php.ini IIRC, if you have root access) OR make
a symbolic link /tmp/mysql.sock --> /path/to/real/mysql.sock
good luck!
Giannis
--
int main(void){int j=1234;/*(c)2002 jgeorgal */
char t[] ="<G> @abcdefghijklmnopqrstuvwxyz.\n";
char*i ="qhui<xfi.df rwgzfizjz.f rwgqqwqtigiz";
while(*i)((j+=strchr(t,*i++)-(int)t),(j%=sizeof
t-1),(putchar(t[j])));return 0;}/* under GPL */
|
|
|
|
|