473,805 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fatal error: Call to undefined function mysql_connect()

28 New Member
Please can some one help with my problem; I am running Apache web server on my lap top, plus a mysql server and php. The version of php currently installed is 5.2.5.
when i write some php to connect to my mysql database server instead of it connecting i get :
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\h tdocs\chephrenr epairs\dataentr yprocess.php on line 16.

question 1 is this:
Is this happening because the version of php i have installed has no support for mysql bundled with it?

Question 2: Are there some versions of php 5 that have no support for mysql at all because it was removed by the php writters and if so which versions of php 5 do have mysql support built in to them that works properly?

I have looked on this forum and found that someone said that mysql support was removed in php 5, but it sdoes not say which version of php 5 it was removed from, neither does it hint as what to do to get php communicating twith the local mysql server??

if questions 1 and 2 have been answered in anther thread on this forum then please where???
Dec 28 '08
49 16299
Dormilich
8,658 Recognized Expert Moderator Expert
@Julian Bowler
if PHP indeed crashes, you won't see anything at all* (not even error messages, which need a running PHP to be displayed).

* I've had this through
Jan 4 '09 #41
Atli
5,058 Recognized Expert Expert
Try this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(E_ALL | E_STRICT);
  3. ini_set('display_errors', true);
  4.  
  5. if(function_exists("mysql_connect")) {
  6.   echo "MySQL extension found<br />";
  7.   if(mysql_connect("localhost", "user", "pass")) {
  8.     echo "Connected successfully";
  9.   }
  10.   else {
  11.     echo "Failed to connect: <pre>". mysql_error() ."</pre>";
  12.   }
  13. }
  14. else {
  15.   echo "MySQL extension not found";
  16. }
  17. ?>
On a working PHP installation, this should show you something, regardless of how your error reporting is configured in your php.ini.

If this shows you nothing, there is something seriously wrong. I would just clear the computer out. Format the HDD (really format, not quick-format!) and reinstall Windows.

Or better yet, install Linux.
Ubuntu Server Edition. Apache + PHP + MySQL all included in the OS installer. Doesn't get much simpler than that :)
Jan 4 '09 #42
Julian Bowler
28 New Member
Very Many Thanks for your responce Atli from Iceland. I have Keyed in your program, well copyed it actually into my editor and ran it on the lap top and the resulting output is as follows:

MySQL extension not found

So that's a definate result is'nt it!!! As far as I can see the program tests for the existance of the php function mysql_connect. and the program in this case reports that is does not exist.

Hence i can only assume that for some reason the PHP Engine can not find what it needs to find to run this standard Mysql connecting function,
I do not know straight off why, and finding out why could be interesting, but where to start....
Well, I tried leaving some of the semi colons off and ,as I hoped, got Parse Errors, so that proves that the error reporting mechanism can work.
One place I could look to see what might be wrong is to compare the outputs of the phpinfo() function both on my XP Home Desk Top and on my XP Home Lap Top to see what the diffrences are because I now have PHP 5.2.8 installed on both machines.
I have now installed Apache 2.2.11 on my Desktop XP Home Service Pack 3 computer, the open ssl version. I have also installed MySQL 5.1 on my Desktop and Lap Top, thus I actually have the same versions of all this software running on both a Desk Top PC and a LapTop Computer.
If I try the same program sent by Atli on my Desktop computer I get this:

MySQL extension found
Connected successfully

if i log on as root using the root password,
And if I log on as another user called test I Get this instead:

MySQL extension found

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'test'@'localho st' (using password: YES) in C:\Program Files\Apache Software Foundation\Apac he2.2\htdocs\ne wsite\mysqlconn ect.php on line 18
Failed to connect:

Access denied for user 'test'@'localho st' (using password: YES)

Ok this means that connecting using the root user is working fine, well root does have access to everything normally and conncecting using this other user called test is being Denied.

---------
Ok need to think about this, I seem to remember that sometimes it is necessary to do a few things to a new MySQL Installation to get new users to work and remember in the past that oftern with some versions of MySQL 4 you needed to remove a couple of Anonymous users, to allow new users into the server...... a MySQL Security issue. well infact when I installed MySQL 5.1 on the Desk Top I did tick the box install Anonymous User during the installation process..... I will research this and look at the MySQL Website to see what that says about user permissiopns and Anonymous users.....
Jan 4 '09 #43
Julian Bowler
28 New Member
The fact that the Laptop reports that the MySQL exstension is not found could er caused by quite a number of things, and I am willing to try a few things out to see if I can track down the problem because I think the answer to why may reveal something interesting.... .

I did not know that thewre was an Ubuntu Server Edition and I am interested in this?? I have actually got Ubuntu 7.04 the normal edition running on the same laptop we are talking about in its own partition, and grub gives me the multi boot menu at start up. But of course this is just the ordinary edition of Ubuntu.

Is it true that if you want Ubuntu and Windows XP Home running on a single Hard Disk you must install XP Home first then Ubuntu?????? I Believe that is the only way round you can do it, and Ubuntu reduces the windows partition size down to make room for a new linux partiton doesn't it!!!??
Jan 4 '09 #44
Dormilich
8,658 Recognized Expert Moderator Expert
@Julian Bowler
technichally no, but otherwise you have to manually reinstall grub (any new windows installation writes the MBR anew)
@Julian Bowler
in principle, yes. of cause you can backup your data and partition the drive before doing any new installations, but this way is the easiest.
@Julian Bowler
even the ordinary Ubuntu installation is capable of running Apache, PHP and MySQL. bear in mind that the ubuntu server edition is meant for server purposes (not desktop usage).
Jan 4 '09 #45
Atli
5,058 Recognized Expert Expert
MySQL extension not found

So that's a definate result is'nt it!!! As far as I can see the program tests for the existance of the php function mysql_connect. and the program in this case reports that is does not exist.

Hence i can only assume that for some reason the PHP Engine can not find what it needs to find to run this standard Mysql connecting function,
I do not know straight off why, and finding out why could be interesting, but where to start....
Ok. This means that the mysql extension is not being loaded.
All the MySQL functions are a part of the MySQL extension, and to use them the extension has to be installed. If it is not, the functions will simply not exists.

To get all this working, there are a few things you need to do.
  1. Add the PHP installation directory to your PATH variable.
    This is done so the system can find all the DLL's there. One of them being the DLL required to link PHP to MySQL.
    Alternatively, you can copy the "libmysql.d ll" file to the Windows directory, although I recommend against this.
  2. Make sure the "php_mysql. dll" exits in the "ext" directory under the PHP installation dir.
    If it does not, download the ZIP package from php.net and copy the file from there.
  3. Uncomment or add "extension=php_ mysql.dll" to the "php.ini" file you are using.
  4. Make sure the "extension_ dir" directive in your "php.ini" file is set to an absolute path to your "ext" dir. That is, for example:
    "C:\php\ext ".
    You could theoretically use a relative path (since the PHP dir is in the PATH variable), but that usually causes problems. An absolute path is much easier to work with.
  5. Reboot your computer. (Windows is slow. It usually take a reboot for it to fully realize that you have changed the PATH variable.)
That *should* get things up and running.

Unless I missed a step. It's been a long time since I traded Windows in for something that actually works :)
Jan 4 '09 #46
Atli
5,058 Recognized Expert Expert
@Julian Bowler
Let me save you some research. (I did it anyways... was curious :P)
(MySQL :: MySQL 5.1 Reference Manual :: 12.5.1.3 GRANT Syntax)
If you allow anonymous users to connect to the MySQL server, you should also grant privileges to all local users as user_name@local host. Otherwise, the anonymous user account for localhost in the mysql.user table (created during MySQL installation) is used when named users try to log in to the MySQL server from the local machine. For details, see Section 5.4.4, “Access Control, Stage 1: Connection Verification”.
To fix the problem, simply delete all the anonymous users:
Expand|Select|Wrap|Line Numbers
  1. DELETE FROM mysql.user WHERE Host='localhost' AND User='';
  2. FLUSH PRIVILEGES;
Or just specify the "localhost" when you create the new users. (Which you should always do anyways.) :P
Jan 4 '09 #47
Atli
5,058 Recognized Expert Expert
@Julian Bowler
No. This is not true :)
Although, this is the simples way to dual-boot Windows along side any other system.

The problem, as Dormilich pointed out, is that M$ doesn't care what is or is not installed on the system before Windows. It simply overwrites the MBR with it's own bootloader, which only supports loading Windows.

You can, however, overwrite M$'s bootloader by simply booting into Linux (like, say, from a Ubuntu Live-CD), and re-install GRUB. (or whatever bootloader you use).
did not know that thewre was an Ubuntu Server Edition and I am interested in this?? I have actually got Ubuntu 7.04 the normal edition running on the same laptop we are talking about in its own partition, and grub gives me the multi boot menu at start up. But of course this is just the ordinary edition of Ubuntu.
The server edition is also just a normal Ubuntu installation.
The difference is that the server edition does not include a lot of the packages that the Desktop edition includes, like the window manager and Gnome.
It is optimized for speed and stability, and comes standard only with the sort of software you would need on a server machine.

You can, of course, install all the stuff that it leaves out.
I've heard of people that always use the Server edition for their desktops, so they can install the X window manager manually and set it up like they want, rather than use the default Desktop setup.
Jan 5 '09 #48
Julian Bowler
28 New Member
On My Desktop PC Running Windows XP Service pack 3 I have used the new MySQL Query Browser (that i installed reciently from the GUI Tools download from the MySQL Web site) to run exactly the commands indicated by Alti, in order to remove all the anonymous users, and it worked perfectly as far as I can work out.!!
So now when I run a little bit of php to connect to the mysql server using a user I have created called test, I get back a message saying:

MySQL extension found
Connected successfully

So thats working perfectly.....

Of course when you do create a new user you should give that user some permissions to the database that you intend to work with, but when you are just connecting to the Database Server i think it is fair to say that any user created by you the administrator will not make a sucessfull connection until the anonymous users that are created at the time MySQL is first installed, are removed!!!!

So in simple terms I think this means that if you install MySQL version 5.1 (in this case) but probably any other version of MySQL; the system will usually or most likley create one or may be more than one anonymous user.

"The effect of this is that it is only possible to connect to that MySQL Server if you do so as the root user."

Also when you install MySQL it will ask you twice for a root user password and you need to give this in order to complete the installation. Plus notice there is a little box asking if you want to create an anonymous user and warning that doing so may make the installation more insecure!!??
Now an interesting question is this:
If you install a MySQL server and during installation you give a root user password and do not tick that box asking if you want to have an anonymous user, do you get a MySQL Server, that allows any user Created by the root user with a password, to connect to that Server??? I am not sure actually...
I am getting quite busy so may not have time to experiment much tomorrow, but I want to do two things, A follow all the advice given by Atli about how to get my lap top to work in respect of php running mysql commands, and B learn why and how a MySQL Server sets up directly after installation with regards to User Access.

I can vaguely remember that when is set up a MySQL Server (possibly version 4.1) probably 3 years ago that it created a couple of anonymous accounts during the installation routine, which needed to be removed if you want anybody to connect to the Server that is not root. i guess that My SQL do this delibrately to make a new MySQL Server completely secure in the first instance!!!?
Jan 5 '09 #49
Julian Bowler
28 New Member
Here is a page that seems to go a good way to answering how MySQL Server sets up initial user accounts during installation >>>

MySQL :: MySQL 5.1 Reference Manual :: 2.10.3 Securing the Initial MySQL Accounts
Jan 5 '09 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9985
by: BT | last post by:
Hi .. a newbie question. I get the following error: Fatal error: Call to undefined function: mysql_connect() in /var/www/html/index.php on line 3. I have the following RPMS installed on RH7.2 MySQL-client-4.0.14-0 I would really appreciate it. MySQL-shared-4.0.14-0 MySQL-server-4.0.14-0 MySQL-devel-4.0.14-0
4
15347
by: gc | last post by:
I'm a PHP and MySQL newbie. I have a feeling a lot of you may have seen this before. I'm teaching myself PHP/MySQL and trying to setup a guestbook. I'm running latest versions of Apache, PHP and MySql on WIN 2000. PHP is installed from the zip file. When serving php docs (code snippets below) I get the messages: "Fatal error: Call to undefined function mysql_connect() " "Fatal error: Call to undefined function mysql_pconnect() "
8
9998
by: Tim Tyler | last post by:
I'm getting fatal errors when executing code - and my error handler is failing to trap them - so I get no stack backtrace :-( The error I am getting is: "Fatal error: Call to a member function fetchRow() on a non-object." What are the available options here? Am I supposed to check I have a real object whenever I perform
1
13671
by: Mike | last post by:
Last weekend I decided to install Apache 2.0.53-win32-x86-no_ssl PHP 5.0.3 Smarty 2.6.7 MySQL essential-4.1.10-win32 I have Apache up (Port 80 blocked at the router and firewall!) and I have got Smarty working. I haven't got around to installing MySQL. I am now in chapter 8 'Error and Exception Handling' of
2
2382
by: inonzuk | last post by:
why strange you ask? here goes: I have been working with Php and Mysql for a week without any problems. Today I tried executing a php page that connects to mysql and creates a new database, I got this error: "Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\test\_debug_tmp.php on line 3". I did some reading on the net and checked all my configuration, and it
2
2003
by: Frobinrobin | last post by:
I am running Win2k3 Server and when I try to use the mysql_connect function I am getting an error: Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\programs\index.php on line 8 Now, I def know I've configured my php.ini correctly (its literally the same as my XP machine) and I know that mysql works fine with PHP as I can run it from the command line :D I've got the files (tried in multiple places - but...
5
4168
by: Grant Nosbush | last post by:
I have searched the newsgroups and the web trying to solve this problem and just can't get it. Maybe someone will be able to help. I am getting the following error when I try to view a test page in my browser. This test page just reads a table in mysql and outputs the results. Fatal error: Call to undefined function: mysql_connect() in /var/web/public/test.php on line 2 I'm using:
5
2783
by: awdsites | last post by:
Hi, I'm a noob with a server so keep that in mind :) Been trying to connect with php to mysql and all I get is: "Fatal error: Call to undefined function: mysql_connect()" I've read and read and can't figure out what is wrong. My current set up is:
9
5268
by: java | last post by:
Hey there, I just removed an elderly PHP4-Installation from my Windows-Box and installed PHP 5.2.1. I used the PHP4-Module as local batchfile- interpreter by E:\ersDHCP>php ./extractLog.php which was perfectly alright and worked well. But now PHP5 fails to run the same script without any modification!
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.