We help IT Professionals succeed at work.

Unable to connect to mysql database

MnInShdw
MnInShdw asked
on
421 Views
Last Modified: 2013-11-05
I have installed PHP & MySQL on a windows server 2003.

I'm trying to connect to a mysql database in a script as following :
$dbhost = 'localhost';
$dbusername = 'root';
$dbpasswd = '1234';
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") ;

But the browser shows this error:
Fatal error: Call to undefined function mysql_pconnect() in D:\Web\wwwroot\lord\requires\db.php on line 10
(line 10 is : $connection=mysql_pconnect........)

mysql version : 5.1
php version : 5.2.1
any kind of help to solve this problem is much appreciated.

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
Hi,

Make sure the mysql module is enabled in your php.ini file. Check phpinfo() to see if the module is loaded

-r-

Commented:
Hi there,

I've found the following:

----------------------------
resource mysql_pconnect ( [string $server [, string $username [, string $password [, int $client_flags]]]] )

Establishes a persistent connection to a MySQL server.

mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

This type of link is therefore called 'persistent'.
---------------------------------

Why not use the mysql_connect(); ?

But tha'ts a different thing,
to get back to the orriginal question:

If you installed mysql after the installation of php be sure to recompile php, then the problem should be fixed.

With kind regards,

HoLy007

Author

Commented:
Which module exactly has to be enabled and how can I enable it.

running phpinfo() brings up the info table which under Additional Modules
I have an empty table.


thanks for your help
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi holy007

what do you mean by compile php?

thanks
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Well, it's getting too complicated.
I have everything as you suggested.
Let me explain it this way.

Different parts of my php.ini :

----------------------------------------------------------------------------------
extension_dir = "D:\Web\php\ext\"
extension=php_mysql.dll

mysql.allow_persistent = 1
mysql.max_persistent = -1
mysql.max_links = -1
mysql.trace_mode = 0
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
--------------------------------------------------------------------------------

php_mysql.dll is located in D:\Web\php\ext

php folder is available to path variable.
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;D:\Web\php;D:\Web\MySql\bin

I tested mysql_connect and mysql_pconnect. Both gave me the same error.

Commented:
Allright, and what if you backup your database and reinstall mysql with the msi?
then the php.ini get's auto configuered.

With kind regards,

HoLy007

P.s.
This is not the best way but it is the simplest way.
CERTIFIED EXPERT
Top Expert 2006

Commented:
Did you need to change the php.ini file? Have you restarted apache afterwards?

I would not go with the reinstalling mysql solution personally.

-r-

Author

Commented:
No there was no need to change anything. And one more point.
It's not running on apache. it's on a windows server 2003
and yes. I restarted IIS (and to be sure, I even rebooted the server)

Commented:
i do agree with roonaan about the reïnstall, but if nothing works you can alway's try that one.

Author

Commented:
I uninstalled mysql and installed it once again.
nothing has changed.

Any kind of help is much appreciated.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi AymanAdam

libmysql.dll is placed my php folder but still I don't have mysql table in phpinfo()

I've subscribed a new thread here:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_22773008.html

with all my info.
I would appreciate any kind of help on this problem.



Author

Commented:
I actually was able to track the problem.
I changed the extension_dir as following and it worked out

extension_dir = "./ext"

for some reasons the full path doesn't worked and I had to use back slashes.


thanks for your help
good to hear,
thanks for the points
Ayman
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.