LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   php / mysql connection problem . (https://www.linuxquestions.org/questions/programming-9/php-mysql-connection-problem-176528/)

MikeFoo1 04-30-2004 10:25 PM

php / mysql connection problem .
 
Hi ,

i get this error :



Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
.
PHP Code:

$con=mysql_connect() or die("Problem".mysql_error());
print 
"Successfully connected.\n";

mysql_close($con); 


The weird thing is that i can connect to mysql in my java programs etc.



Quote:

mysqladmin status
Uptime: 1791 Threads: 1 Questions: 5 Slow queries: 0 Opens: 6 Flush tables: 1 Open tables: 0 Queries per second avg: 0.003

also,
Quote:

mysqladmin ping
mysqld is alive
So, i am guessing i have to edit something to get it working.

ps i am running Slackware 9.0 , default mysql installation.

the phpinfo(); gives this:

Quote:

Active Persistent Links 0
Active Links 0
Client API version 3.23.49
MYSQL_MODULE_TYPE builtin
MYSQL_SOCKET /tmp/mysql.sock <----
MYSQL_INCLUDE no value
MYSQL_LIBS no value
i have edited the php.ini and i have the following:

Quote:

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =/var/run/mysql/mysql.sock

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =
Do i have to edit anyting else ?

Any help would be appreciated.

Mara 05-01-2004 05:10 PM

It may be a stupid question, but...do you run mysql_connect() without or with parameters? If you don't give any parameters, do the defaults fit?

From php.net:
Quote:

The following defaults are assumed for missing optional parameters: server = 'localhost:3306', username = name of the user that owns the server process and password = empty password.

MikeFoo1 05-01-2004 06:33 PM

Quote:

Originally posted by Mara
It may be a stupid question, but...do you run mysql_connect() without or with parameters? If you don't give any parameters, do the defaults fit?

From php.net:

Yes, i do have host,usrer,password fields defined.Still, can't connect.

If i edit the php.ini file , it is supposed to change when i call phpinfo(); right ?

Currently i have :


Quote:

Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value

mysql.default_socket no value no value <-but i already changed it to /var/run/mysql/mysql.sock

mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off
Could someone post their php.ini here ?


Thanks.

Mara 05-02-2004 05:22 PM

In my case (php.ini file) :
Code:

[MySQL]
mysql.allow_persistent = On
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off

(and it works)
So it looks it's rather not a php.ini problem in your case.


All times are GMT -5. The time now is 04:44 AM.