PHP 5 cant connect to Mysql 5

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
zep
Forum Newbie
Posts: 3
Joined: Thu May 08, 2008 12:12 pm

PHP 5 cant connect to Mysql 5

Post by zep »

I am moving to a dedicated server (yay!) from a shared hosting package, here are the details:
php 5.2.5
mysql 5.0.45
linux fedora
litespeed (apache interchangeable) server

I compiled php5 with the following:
--with-mysql --with-mysqli --with-zlib --with-gd --enable-mbstring --with-mhash --with-mcrypt --with-dom --enable-simplexml --with-pdo-mysql --with-iconv --enable-shmop --enable-track-vars --enable-sockets --enable-sysvsem --enable-sysvshm --enable-magic-quotes


(above verified with phpinfo.php, does litepeed show loaded modules like apache? There is no litespeed info section like apache...)

added to the php.ini file :

extension=apc.so
extension=suhosin.so
extension=mysql.so
extension=mysqli.so
extension=pdo_mysql.so
extension=pdo.so
extension=php_mysql.so
extension=libmysql.so

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

my phpinfo is showing the following for MySql:

Active Persistent Links 0
Active Links 0
Client API version 5.0.45
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib/mysql -lmysqlclient

My php scripts work like a charm, but they can't connect to MySQL! I have been drudging through forums looking for something to try, but have not found a solution. I have thus found this forum, which seems to have the most knowledgeable members.

Please lend a sugestion, as I am under the gun to get this done, I really apprecite the help!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP 5 cant connect to Mysql 5

Post by Christopher »

Check your logs. I am not sure you can have both mysql and mysqli at the same time.
(#10850)
zep
Forum Newbie
Posts: 3
Joined: Thu May 08, 2008 12:12 pm

Re: PHP 5 cant connect to Mysql 5

Post by zep »

I checked the phpinfo on my old host, and they have both running so I don't think its an issue with that. here is the info from the mysql section of phpinfo:

mysqli
MysqlI Support enabled
Client API library version 5.0.32
Client API header version 5.0.32
MYSQLI_SOCKET /var/run/mysqld/mysqld.sock

Directive Local Value Master Value
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.reconnect Off Off

I think it has something to do with permissions or the way they talk to each other, Ill look for the erropr logs, but my server shows no related errors, but maybe PHP has one ?

Thanks for replying, I appreciate the help, and I hope to get this issue sorted out with your and your forums help!
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: PHP 5 cant connect to Mysql 5

Post by EverLearning »

And how are you trying to connect to database and what error do you get? Show us the code.
zep
Forum Newbie
Posts: 3
Joined: Thu May 08, 2008 12:12 pm

Re: PHP 5 cant connect to Mysql 5

Post by zep »

thanks everyone, it was the code that was the issue, or actually the password I had for the database login (I used the old pw) :banghead:

anyway, for those of you troubleshooting a similar issue and winding up in this thread try the following script to do a very simple test to the connection, put it in a plain text file (or use you php ide) and save it as anything really (iI used mysql_test.php) slap it on your server and type the location into your browser.

Code: Select all

 
<?php
$link = mysql_connect('localhost', 'sbi', 'sbi123');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
 
Hope my despair helps somebody! Again thanks for answering this thread.
Post Reply