View Full Version : Database connection ...?

04-30-2004, 11:12 AM
Hi all,

i have just installed php/mysql (which is working) on my linux box .The problem is, i don't seem to be able to get rows from the database.



echo("Connected !!!"); //<----- prints connected :)

$result=$dB->execute("insert into Music values(1987,\"DDD\",23)");
echo("Executed"); // <-- does not appear :confused:

Can anyone help me ?

04-30-2004, 12:41 PM
You are missing some braces

if(DB::iserror()) {
} else {
echo "Connected !!!"; //<----- prints connected :)

05-01-2004, 12:31 AM
Hi ,

i get this error :

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

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

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

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:

Active Persistent Links 0
Active Links 0
Client API version 3.23.49
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_LIBS no value

Any help would be appreciated .

05-01-2004, 02:17 AM
PEAR::execute() is used when passing a prepared() statement , for a simple query use query()

echo("Connected !!!");
$sql='insert into Music values(1987,"DDD",23)';
$result = $dB->query($sql);
& check the result !
if (DB::isError($result)) {
die ($result->getMessage());

05-02-2004, 09:54 PM
Still, can't connect.

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

Currently i have :

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 ?


05-03-2004, 02:50 AM
doh , totally missed the connection problem post ~
on my fedora install the default port,socket,host and user are all blank but it all still works

check what your mysql configuration says (check path)..

`cat /etc/my.cnf | grep socket`

also note that if you made changes to php.ini you need to restart apache (if PHP is an apache module) before the changes will be implemented.

05-03-2004, 03:58 AM
in my /etc/ i have :


but no my.cnf.

cat my-small.cnf gives:

# Example mysql config file for small systems.
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld deamon
# doesn't use much resources.
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
# ~/.my.cnf to set user-specific options.
# One can in this file use all long options that the program supports.
# If you want to know which options a program support, run the program
# with --help option.

# The following options will be passed to all MySQL clients
#password = your_password
port = 3306
socket = /var/run/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
port = 3306
socket = /var/run/mysql/mysql.sock
set-variable = key_buffer=16K
set-variable = max_allowed_packet=1M
set-variable = thread_stack=64K
set-variable = table_cache=4
set-variable = sort_buffer=64K
set-variable = net_buffer_length=2K
server-id = 1

# Uncomment the following if you want to log updates

# Uncomment the following if you are NOT using BDB tables

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#set-variable = innodb_buffer_pool_size=16M
#set-variable = innodb_additional_mem_pool_size=2M
# Set .._log_file_size to 25 % of buffer pool size
#set-variable = innodb_log_file_size=5M
#set-variable = innodb_log_buffer_size=8M
#set-variable = innodb_lock_wait_timeout=50

set-variable = max_allowed_packet=16M

# Remove the next comment character if you are not familiar with SQL

set-variable = key_buffer=8M
set-variable = sort_buffer=8M

set-variable = key_buffer=8M
set-variable = sort_buffer=8M


Any help ?

05-03-2004, 04:21 AM
ok, try copying say /etc/my-small.cnf to /etc/my.cnf (as is) and restarting everything (mysql & apache), + check that your php.ini mysql.default_socket matches that in the my.cnf (or leave it blank)

05-03-2004, 10:35 AM
hey, it's me again.I have tried lots of stuff but cant get it working.What the yakk-snarf does it need ?Where does mysql read the socket ,host etc stuff from ?

I am going insane :eek: .

05-03-2004, 11:00 AM
lol , sorry to laugh but I having similar issues with firebird .. everything & dog can talk to it but PHP :mad:

but err , if PHP and MySQL both claim to be using the same socket (& port (3306)) & mysql is running then I dont see why it won't work , MySQL should look first in /etc/my.cnf for its configuration , have you done a `locate my.cnf` ? to see if there are any others about ? also did you
configure php --with-mysql=/path/to/mysql
? or let it use the defaults?

05-03-2004, 11:15 PM
Hey!I am at uni right now but i will try "locate my.cnf" later.As for the --config, no i did not use the with-mysql option(the reason being i did not compile it[mysql] from the source.I assumed that if i don't put the path to the source then it's the same as not puttinng it at all.Am i wrong?).

BTW i just noticed that you are from Australia, i am in NZ :-).

05-04-2004, 02:38 AM
I found this : http://www.webhostingtalk.com/showthread.php?threadid=8514

05-04-2004, 05:46 AM
Ok, i have got it working :-) .The solution was very simple indeed.What i did was i just created a symbolic link to /var/run/mysql/mysql.sock ( ln -s /var/run/mysql/mysql.sock /tmp/mysql.sock ).

Anyone can advise good php books(ebooks) ?

BTW thanks to the moderator :thumbsup: .

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum