By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,026 Members | 2,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,026 IT Pros & Developers. It's quick & easy.

Fatal error: Call to undefined function mysql_connect()

P: 28
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\htdocs\chephrenrepairs\dataentryproc ess.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 #1
Share this Question
Share on Google+
49 Replies


Dormilich
Expert Mod 5K+
P: 8,639
short answers:
1. probably

2. that depends on the distributors of the according PHP build. I think the PHP 5 source code has general support, may it be enabled by default or not.

long answers:
I'm not aware that MySQL support has been cancelled on PHP 5. nevertheless, you can get proof of that by looking at the phpinfo() page. just on top should be the configure commands (the ones that tell you with what preferences your PHP was build). if you can't find the option '--with-mysql=/$path' ($path is the path to PHP's mysql files)(or alternatively there is the option '--without-mysql') what I suspect from the error message, then you have to either get another PHP build or you have to build it yourself...

to avoid reinstalling you can try the MDB2 PEAR package (at PEAR :: The PHP Extension and Application Repository)

regards
Dec 28 '08 #2

pbmods
Expert 5K+
P: 5,821
Heya, Julian.

Check out this page for more information:
PHP: Installation - Manual
Dec 29 '08 #3

P: 28
thanks to the two people that have replied, pbmods and dormilich!
I have ran phpinf() and looked at the resulting page, Under Apache environment is says in the PATH Section
C:\Program Files\PHP\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDO WS\System32\Wbem;C:\Program Files\MySQL\MySQL Server 4.1\bin;"C:\Program Files\Symantec\Norton Ghost 2003\"
also in the environment section and th php variable section there is MySQL mentioned!
So i do not know what this means unfortunately, I have managed to download some other versions of php 5, so I am going to remove my present version of php completely and leave the configuration file for Apache alone and then install a different version of php on the laptop?
The question becomes which version of php will definitely have Mysql support bundled in it ?? I do not know, is there a place where i can simply answer this question please?? thanks inadvance Julian
Dec 29 '08 #4

P: 28
Before I do try what i said in my previous post about trying a different version of php 5 i am going to follow the advice that pbmods said which essentially points to some helpful information on installing php I am essentially going to try to manually reconfigure php to recognise the mysql local server correctly and my results will be posted latter on here in this thread julian
Dec 29 '08 #5

P: 28
I Read on the php site that in order for mysql support to be working that the file php-mysql.dll must be enabled inside the php.ini configuration file. inside the php.ini file i can find no reference to php-mysql.dll

Also, there is no file with the name php-mysql.dll inside the php directory anywhere at all...... does this mean then that php 5.2.5 simply does not have any MySQL Support??? ??
Dec 29 '08 #6

Dormilich
Expert Mod 5K+
P: 8,639
@Julian Bowler
Maybe it's not in the PHP folder but the MySQL folder, try searching all folders of the PATH variable. the $PATH section clearly denotes, that MySQL can be used (otherwise, why putting the MySQL path in?).

Alas, since I run PHP on a Mac I can only guess further.....
Dec 29 '08 #7

ak1dnar
Expert 100+
P: 1,584
in a windows installation, all the extensions goes to a directory named <php-installtion-path>/ext

there you need to add this line in php.ini to load the extensions from that dir. make sure it is already there.
Expand|Select|Wrap|Line Numbers
  1. ; Directory in which the loadable extensions (modules) reside.
  2. extension_dir ="C:\Program Files\PHP\ext"
  3.  
If the php_mysql.dll is available on the /ext dir, you can load it to the php environment like this.
Expand|Select|Wrap|Line Numbers
  1. [PHP_MYSQL]
  2. extension=php_mysql.dll
  3.  
If you have used a .msi file for the installation, just try to reinstall it and select a custom installation from there. you can then enable relevant extensions from "extras" menu of the installer.
Dec 30 '08 #8

P: 28
many thanks for reply from ak1dnar. i have tried a few things that did not work, not i hasten to add. the thing you wrote about in you post to this thread..
yesterday I removed the old folder containing php 5.2.5, and it seems that removing the php directory is the way to uninstall php!!! Then i found a CD rom in a book called Sams Teach Yourself PHP, MySQL and Apache. This CD has on it PHP 5.0.2 in fact,and also a program that unzips all the files to C:/PHP5. so i did that.
than i found the file inside this directory called php.ini-recommended and renamed it php.ini.
then i copied this file called php.ini into the windows directory.
then i copied the file php5ts.dll into C:\windows\system. then i went to the apache configuration file called httpd.conf and did some editing, here is what i did;
at the end of the section where you see lots of lines saying Loadmodule.......
I added:
LoadModule php5-module c:/php5/php5apache2.dll
this line above must be exactly as is above otherwise Apache will not be able to start
then i found section starting
#
# AddType allows you to add or overide

and i added this line:
AddType application /x-httpd.php .php .phtml .html .php3
then i saved the apache configuration file and then restarted apache
This seems to have worked..... but i am still trying to understand exactly why??
I am putting up some stuff About this at my web site which will appear at:
chephrenrepairs.com - Home
i do want to understand more about how php and mysql interact, it seems to me that some php versions do simply have inbuilt MySQL support and some do not have this inbuilt???
Dec 30 '08 #9

P: 28
ok... i am looking at your post ak1dnar, and i notice that with my new installation of php which is as i say version 5.0.2, inside the directory C:\PHP5 there is another directory called /ext.
Inside this directory there are lots of .dll files and amongst them there is php_mysql.dll and php_mysqli.dll
Also i am looking inside the new php.ini file that now resides inside C:\windows.
and in this file i find these lines:
;extension=php_msql.dll
;extension=php_mysql.dll

i find these lines in the part of the file where it starts:
;Windows Extensions
;Note that ODBC support is built in, so no dll is needed for it.
;


is it correct that if lines in php.ini start with a ; that they are in fact turned into comments and hence ignored???
therefore both these lines will be ignored, so i do not at the moment understand, what is it that actually allows php to be able to run successfully code to connect to a mysql server along with of course lots of other mysql type functions ???
Dec 30 '08 #10

Dormilich
Expert Mod 5K+
P: 8,639
@Julian Bowler
yes, that's correct.
Dec 30 '08 #11

P: 28
when i said in the previous but one posts that what i did worked, i.e. got php to run mysql functions correctly, well that's not true because when i run the correct php to connect to the local MySQL Server, i did not get the fatel error message suggesting that the function mysql_connect() has failed to work , instead I get just a blank page, with no writing in it at all??!
so what does that mean? does it mean that any of the php is working at all/ I am going to continue to try to figger this out, and what i find out will be in this thread on this forum i hope shortly, watch this space...!!!!???
Dec 30 '08 #12

Dormilich
Expert Mod 5K+
P: 8,639
that looks like a PHP runtime error (e.g. a defect library). try to figure out which function may cause this (e.g. if a DB library is defect, php code without DB functions should work fine, something like that)
Dec 30 '08 #13

P: 28
if i run a little php to echo some text to the screen that works, but what about the function $conn = mysql_connect("localhost","USER_NAME","PASSWORD");
as we know there a lots of mysql php functions, but the one i am using simply is designed to make a connection to a database. it should either work or not work?
I need to look at whether error reporting is switched on or off, and what level of error reporting is enabled and possibly other things also. i need to also test to see if some other php functions not related to MySQL work ok. i will do some testing...
Dec 30 '08 #14

Dormilich
Expert Mod 5K+
P: 8,639
@Julian Bowler
basicly yes. but the mysql library may be corrupted (then you get no output at all (not even error messages)) or there may be an error in the php.ini....

regards

one more thing: never ever post passwords (use something generic like "password")
Dec 30 '08 #15

P: 28
that Old Estonian proverb comes to mind; If you think things are really bad don't worry yourself, things will definitely get worse.....

I have figured out that a simple echo command works fine so php in general seems just fine, next i will try to see firstly what the level of error reporting is at present and then play at changing it to see what happens....
Dec 30 '08 #16

P: 28
oh yes, it is ok the password i posted is fake, it is not like the real one that will eventually be used on the live server... but thank you for mentioning this it is a good and valid point. on the real program i will us user names and passwords that will not be posted anywhere in any forum.
Dec 30 '08 #17

Dormilich
Expert Mod 5K+
P: 8,639
then I'm relieved.

regards
Dec 30 '08 #18

P: 28
I have now looked at php.ini and in it there are error handlingg andd loging section and in here there is
error_reporting = E_ALL
and
display_errors = Off
it is this line that is ensuring that no errors are being sent to the screen, i have changed it to say display _errors = On and then stopped and started Apache and hay now i see the message:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\chephrenrep........... at line 20
So we see that the mysql function is still not working.....

so will go back to look at all the posts in this thread and see if i can try some of the ideas presented as well as googling the problem once more...??????.... what i discover will be posted here, any help from anyone in the know with php 5 configuration would be welcome along with the other people that have kindly posted help.. ...
Dec 30 '08 #19

Dormilich
Expert Mod 5K+
P: 8,639
you could try the WAMP package....
Dec 30 '08 #20

P: 28
as per the post by ak1dnar previous, i tried putting this line into php.ini
extension = php_mysql.dll
and then saving the file and stopping and then restarting Apache, but what happens is that Apache will not start, and instead we see a message on the screen that says:
PHP Startup: Unable to load dynamic library 'C|PHP5\ext\php_mysql.dll' - The specified procedure could not be found.

so please does any one know what this means and does it have any relavance to my problem which is that I can ot run a php script that simply calls the mysql_connect() function??? ?

What is missing ? Is php unable to run any mysql type function and is the reason possible to discover?
I come back to this question, what is needed in a php installation to be able to run all mysql functions to communicate with a local MySQL Server??
And which versions of php work with MySQL? Has Mysql support ben remved form some or all php 5 versions, I am sure I had it all working fine previously with a php 4 version!!?
is the next thing to try, removing php 5.0.2 and install a php 4 version?
Dec 30 '08 #21

P: 28
many thanks for Dormilich response, yep i could try a WAMP Package but one thing that concerns me is are there any WAMP Packages that work reliably, and also if the WAMP Package does not work properly can it be uninstalled without messing up my computer.
Has anybody any experience of WAMP Packages that work well and are straight forward to install, of course i would need a WAMP Package for use on windows XP Home.....
Finally, would I need to uninstall Apache MySQL and PHP prior to installing a WAMP Package??? What set up of the MySQL part would be required, normally in My SQL you need t remove some default users, and create some new users to get MySQL Server to work I do believe.?
Dec 30 '08 #22

Dormilich
Expert Mod 5K+
P: 8,639
@Julian Bowler
the path looks strange. I'd have expected something like 'C:\PHP\...'
@Julian Bowler
I have 5.2.8. working (through MDB2) and so do thousands of others.
Dec 30 '08 #23

P: 28
PHP 5.2.8 working with MDB2, please tell me what is MDB2 is that a relational database like MySQL that can be ran on a web server? I have not herd of MDB2?
ta..
Dec 30 '08 #24

Dormilich
Expert Mod 5K+
P: 8,639
in short MDB2 is a Database Abstraction Package provided through PEAR. see PEAR :: Package :: MDB2 (it makes working with databases easier)

note: MDB2 for MySQL uses PHP's mysql functions
Dec 30 '08 #25

P: 28
many thanks for your reply, I am tomorrow going to remove php 5.0.2 and then try installing php version 4.4.7, this is the zipped win32 version. I will then attempt to configure this to work with MYSQL that is installed and running on my lap top. I have read on the internet that php 5 does not have MySQL Support built into it and that it has to be configured manually, but I have tried quite a few things so far and i still get the
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\chephrenrep.....
every time i run the php script calling this function.

IF PHP 4.4.7 will not solve the problem I will most likely rebuild the entire Lap Top from scratch starting with using the original cd to put it back to how it was in the factory and then installing Apache, php 4.4.7 which i do hope will work, and then Mysql 4.1.

All replies to this thread have been very helpful.... intend to add to this thread tomorrow
Dec 30 '08 #26

ak1dnar
Expert 100+
P: 1,584
Sorry guys, I was quite busy with my works last day. :(

Ok, back to the questions. My first recommendation is do not revert back to Php 4.x.x as now we have Php 5.x.x which is more powerful and stable.

Your problem is some what strange to me. may be as "Dormilich" said, you have used some corrupted version of php installer.

Still I suggest you to install MySQL, Php, Apache as separate installations. Doesn't matter if you happy with WAMP also, it a good tool. But I still like to configure them individually.

If you need to do it from scarch here we go !

Uninstall Php, MySQL, apache from your system.and restart your pc.

Install Apache
Download apache_2.2.11-win32-x86-openssl-0.9.8i.msi and install it with the default settings.

Install MySQL
Download and install mySQL from here MySQL 5.1 and install it with default settings

Install Php
Now get thePhp 5.x.x from php.net, PHP 5.2.8 installer is better.

When Installing select the Apache Version 2.2.x as your target web server.

Provide the apache configuration dir when asking.
ex: C:\Program Files\Apache Software Foundation\Apache2.2\conf\

Then you can select the Extensions > MySQL and enable it. (Do not select all the extensions as it will brake the configuration)

Restart the Apache or your PC.

Now create a test script ( phpconfigtest.php ) with these lines of code and put it to Apache Doc Root. (Hope you know where it is)
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. phpinfo();
  3. ?>
  4.  
exceute the page as http://localhost/phpconfigtest.php
you will see the Php confuguration info in detail in the page. find the "mySQL" details area. if it is there and if mysql support enabled, you are good to go with Php-MySQL.

Happy coding.
--ak1dnar
Dec 31 '08 #27

P: 28
very helpful response from ak1dnar,many thanks... yep it is possible that some file or files are corrupted it does actually happen!! As to uninstalling Apache, well it appears in the add and remove programs feature of Control Panel, so i guess can be removed using that. also PHP 5.2.2 also appears in add and remove programs, but is is not there as i removed its directory before, that is bizarre and plan bonkers!!

Hence i will try to remove Apache using add and remove programs and do the same with MySQL and MySQL Query Browser and MySQL Administrator. then i will remove the current php directory and remove all the files i copied to C:/Windows and to C:/Windows/system and then finally start again with the pieces of software recommended by ak1dnar.

just to be clear, you can test whether or not php is working by writing a program like:
<?php

phpinfo():
?>
and running it and you will see a blue page, but you can not test a php connection to a MySQL database unless you write some specific functions to connect and to use a database etc, and to do this you need of course an actual database and a user to actually exist first, and probably a table in that database would be also very useful me thinks......
Dec 31 '08 #28

Dormilich
Expert Mod 5K+
P: 8,639
@Julian Bowler
jepp.

@Julian Bowler
correct, the phpinfo() tells you whether PHP correctly recognized its MySQL part. testing the mysql functions indeed requires a database, user, ... which are usually unknown to php.ini
Dec 31 '08 #29

P: 28
I have now installed all recommended by ak1dnar, and it has all installed fine,but when i run the mysql _connect function in a web page, i get a blank page, absolutely nothing, white screen.....
I have checked that in php .ini
and there is in it
error_reporting = E_ALL
and
display_errors = On, and i restarted the Apache server,
so what is going on why will it apparently not work. what should i try to do next??
Jan 1 '09 #30

ak1dnar
Expert 100+
P: 1,584
using mysql_connect() doesn't return any out put value to you, but you will get a link identifier.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  3. if (!$link) {
  4.     die('Could not connect: ' . mysql_error());
  5. }
  6. echo 'Connected successfully';
  7. mysql_close($link);
  8. ?>
  9.  
  10.  
Jan 2 '09 #31

P: 28
Many Thanks for the reply by Ak1dnar, I will try out the code that you suggested tommerow morning and I also wonder if I need to change anything in my software firewall running on the lap top: and wonder if this could be causing any problems, or indeed be part of the problem i appear to be having???
I imagine that there are a number of ways of testing to see if a connection to the database has been established, but the method detailed in the last post seems sound and very neat, and tests I think whether the link identifyer does not exist....... possibly when building a program in php in a test environment it is good to test every single stage and to output messages and indicators to the web page to show exactly what has happened!!!
Of course in the final live program on a live web server many of these messages need to be removed to make the output make sence and be uncluttered.... I will add to this thread I hope tommarow..
Jan 3 '09 #32

P: 28
I have tried running some very simple php commands , stuff like echo 'at line 10'; and when it is good php it echos the words to the screen, but when i introduce a deliberate mistake like for example...
echo 'at line 10 ;
then instead of getting an error showing in the web page i get just a blank screen, it is as if no errors are being shown at all.!!!!
I have looked inside the php.ini file and it says this....
error_reporting = E_ALL
and this.....
display_errors = On
and
display_startup_errors = On

I expect that when i make an error in my php that a warning or and error message will appear inside the web page, but it seems that nothing does at all.
i do not understand why, and as far as i know error reporting is switched on to report all errors as per the lines in php.ini that i have detailed in this post.

Are there any other lines in any other conflagration files that would turn off error reporting?? I will look up more about error reporting in my php books and will investigate whether switching off my software firewall makes any difference also. I may even try installing exactly the same software onto a desktop pc and see if the same problem can be reproduced.
I managed to find some tools for creating a mysql system tray monitor that appears in the task bar, that gives you both MySQL Administrator and MySQL query browser, but the msi installed version of this did not work , so i found a zipped version and unzipped it into program files and this does work once you figure out which files are the executable ones you need to start things up..

Only recently i had the fatal error message in the web page that is right at the start of this thread, which prompted me to start asking questions right at the start........
Jan 3 '09 #33

P: 28
If i put into a php script this line :
error_reporting(E_ALL); and save it and put to the local Apache Server. I still see no warning or error in the browser even if i make a deliberate mistake like for example leaving a semicolon off a line of php.
so why could that be...???
Jan 3 '09 #34

Dormilich
Expert Mod 5K+
P: 8,639
if you test it with mixed html and php and you don't get any output (even in the source (for that to test write the html part)) then you probably have a runtime error, i.e. your installation is broken somewhere.

example:
Expand|Select|Wrap|Line Numbers
  1. // even if PHP fails but runs, the html tags should be printed
  2. <html> 
  3. <body>
  4. <?php phpinfo() ?>
  5. </body>
  6. </html>
Jan 3 '09 #35

P: 28
Ta very Much for your responce Dormilich I will try exactly what you suggest in you previous post and see what happens.
J
Jan 3 '09 #36

P: 28
ok I decided to install all the software suggested by akidnar onto a separate Desktop pc running XP Home Service pack 3. Then I installed also The MySQL GUI tools giving me MySQL Administrator and MySQL Query Browser, then I set the MySQL System tray monitor to start at log on.
Then I Installed Dreamweaver and configured it to point to the lovcal Apache Server.
Then I wrote this:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Page one here</title>
  6. </head>
  7.  
  8. <body>
  9. <p>you r here</p>
  10. <?php
  11. echo 'asd';
  12. $link = mysql_connect('localhost', 'root', 'passwordx');
  13. if (!$link)  {
  14.                 die('Could Not Connect'. mysql_error());
  15.               }
  16.             echo 'Connected to  Mysql Server OK';
  17.             mysql_close($link);
  18. ?>
  19.  
  20. </body>
  21. </html>
  22.  
this shows not the correct password!!!

The out put i got was this:

you r here
asdConnected to Mysql Server OK

Thus i think proving that I have a conection to the MySQL Server.
Of course it is still not working on the lap top, but I think the answer to that one is to rebuild the laptop from scratch with XP Home on it and all the patches and then try again>??!"!!

i think that I made one mistake i think when you write the mysql_connect function you should use single quotes around each parameter in the brackets not Double Quotes....... is that right?
Jan 3 '09 #37

Dormilich
Expert Mod 5K+
P: 8,639
@Julian Bowler
shouldn't matter. the only difference is, that double quotes will be parsed (for variables) and single quotes not at all. personally I prefer to store these values in constants and call these (because I can use a central config file for all my constants, regardless how often and where I want to call the DB*).

regards

* which is not quite true because I use the MDB2 singleton, and that needs the parameters only once, no matter how often used.
Jan 3 '09 #38

P: 28
As soon as i can i am going to rebuild my laptop starting with the CDS that came with it when it was new, then installing any hardware drivers that the machine needs, then of course installing all the applications that were bundeled with the machine from the manufacturer then installing anti virus / spywear and a software fire wall, then installing of course any other software that might protect the machine from nasty software attacks, then finally Apache html server , then MySQL Server and Client then PHP 5, then I will ensure that the php.ini file has in it the right settings for a development environment, i want to see message when php crashes.
Finally i will need a configured web editor, I will be using what many consider to be the industry standard for this job.
then i will test out some of the principles written about in this thread if you want to follow what happens go to the Computer Fixer Blog Computer Fixer
or go to :chephrenrepairs.com - Home
Jan 3 '09 #39

P: 28
I think it is the case that when you do install PHP, that by default it is installed in a way that has sending error messages to the screen turned OFF, this means that if PHP crashes you may see no notices or warnings in the Web Page conserned. In order to change this you do need to edit the php.ini file manually and then to save it and then you must stop and restart the Apache Web Server I think!!
In a live web environment you will probably want error messages turned off in a local test environment you will probably want them all turned on!!

I have not rebuilt the laptop yet, but I now strongly suspect that it's inability to run MySQL PHP functions is not due to necessarily the right MySQL support being in PHP, but instead is due to some unidentified software problem that exists on my Lap Top!!
As soon as I have got the appropriate software installed on the laptop I will be testing simple things like: Connecting to the Local MySQL Server, Selecting a Database, Selecting and then updating a Table in that Database and so on!!!!?

Jan 4 '09 #40

Dormilich
Expert Mod 5K+
P: 8,639
@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
Expert 5K+
P: 5,058
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

P: 28
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'@'localhost' (using password: YES) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\newsite\mysqlconnect.p hp on line 18
Failed to connect:

Access denied for user 'test'@'localhost' (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

P: 28
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
Expert Mod 5K+
P: 8,639
@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
Expert 5K+
P: 5,058
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.dll" 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
Expert 5K+
P: 5,058
@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@localhost. 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
Expert 5K+
P: 5,058
@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

P: 28
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

P: 28
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

Post your reply

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