Jump to content


Photo

Call To Undefinded Function mysql_connect


  • This topic is locked This topic is locked
43 replies to this topic

#21 Contradiction

Contradiction
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2006 - 05:49 PM

sorry dudes am running Apache 2.2.3 & php 5.2 and they are running in perfect way,i just got the mysql error :(,plz help, i posted the details in prev messsage

#22 Contradiction

Contradiction
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2006 - 06:30 PM

yeppppppppppppppppy it worked, the problem that i was using php 5.1 before but it was not compatable for apache2.2.3 so i downloaded php 5.2 so it has some files compatable with apache 2.2.3, but before that i placed php5ts.dll version 5.1 in the apache bin file, and that was making troubles for my enabling mysql, so after removing this file from the apache bin folder, it is working now :D,
laterz ;), thx dudes :P

#23 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 13 August 2006 - 09:05 PM

Ok, I've followed the directions to the T..I think.  I've modified the PHP.ini file to call for the extensions dir and php_mysql.dll...libmysql.dll is in the winnt directory (I'm running Win2K).  PHP runs by itself just fine.  MySQL runs by itself just fine.  Whenever I try to insert data in a DB via PHP, the web page comes up blank...it shouldn't do that...any ideas??

#24 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 August 2006 - 10:56 AM

Does it connect fine to the database? Ie:
$conn = mysql_connect('localhost', 'user', 'pass') or die('Unable to connect to the MySQL server<br /><br />' . mysql_error());

mysql_select_db('db_name') or die('Unable to connect to the database<br /><br />' . mysql_error());

echo "Connected to MySQL and the database fine";

If it does then it most probably an error withing your SQL Query. Add this -
or die(mysql_error());
to end of the the mysql_query function when you perform your query.

Also you might want to post a help topic in the PHP Help forum. If you query is failing.

#25 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 16 August 2006 - 02:46 AM

Ok, I fixed the problem making the screen come up blank.  I didn't have short tags enabled (IE: had to use <?php instead of <?) Now I'm getting the following error:

Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\PHP\database.php on line 28

I know the code is right because it worked on a different server, but somehow PHP isn't talking to MySQL...I've set the extension_dir = "C:\PHP\ext" and extension="C:\PHP\ext\php_mysqli.dll"

MySQL section of PHP.ini is as follows:

[MySQLi]

; Maximum number of links.  -1 means no limit.
mysqli.max_links = -1

; Default port number for mysqli_connect().  If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysqli.default_port = 3306

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysqli.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysqli.default_host = localhost

; Default user for mysql_connect() (doesn't apply in safe mode).
mysqli.default_user = dsartain

; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysqli.default_pw =

; Allow or prevent reconnect
mysqli.reconnect = On

PHP/MySQL Connection Code is below:

$dbconn = mysql_connect("localhost","dsartain","marines"); mysql_select_db("test2",$dbconn); 
$query = "INSERT INTO `contacts` VALUES('$firstname','$lastname','$address','$apt','$city','$state','$zip','$email','$phone1_type','$phone1','$phone2_type','$phone2')";
$runquery = mysql_query($query,$dbconn);

PHP works fine in and of itself, same thing for MySQL.  They just don't talk to each other...any ideas??

#26 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 August 2006 - 08:20 PM

You cannot do this:
extension = "C:\PHP\ext\php_mysqli.dll"
You need to setup the extension_dir to point to where your PHP extensions are loacted

Then you scroll down and enable the php_mysql.dll extension. You enable this extension for the mysql_* functions.
If you are using the mysqli_* functions then you enable the php_mysqli.dll function.

#27 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 17 August 2006 - 02:39 AM

You need to setup the extension_dir to point to where your PHP extensions are loacted


Isn't that what "C:\PHP\ext" does??

And I'm using MySQL Server 5.0, so from my understanding I'm using the mysqli.dll file, so what do I need to do differently to call it?  I've tried both extension = "C:\PHP\ext\php_mysqli.dll" and
extension = "C:\PHP\ext\php_mysql.dll", which is the way the php.ini came, only I deleted the semicolon and added the "i" in php_mysqli.dll when php_mysql.dll didn't work....

#28 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 August 2006 - 03:01 PM

You cannot do extension = "C:\PHP\ext\php_mysqli.dll" to enable a PHP extension. What you need to do is uncomment the extension you want to enable in the php.ini. For example if you want to enable the mysql extension you'll need to find the following in the php.ini:
;extension=php_mysql.dll
Then you remove the semi-colon from the start of that line. Or if you want use the MySQL Improved Extension you need to add extension=php_mysqli.dll to end of the extension list in the php.ini

Now before you save the php.ini and restart the server you need to make sure the extension_dir directive is setup correctly. To setup the extension_dir scroll up and find this:
; Directory in which the loadable extensions (modules) reside.

Below that line should be the extension_dir directive. By defualt it will be this:
extension_dir = "./"
Change ./ to C:\php\ext
PHP will use this directive to find the extensions.

Now save the php.ini and restart your server. Note: make sure a file called libmysql.dll (with is found in the root of the PHP folder (C:\php)) is either in the C:\WINDOWS folder. Note if you are on Win2k or on Windows Server xxxx you put it in the C:\WINNT folder

Also it doesnt matter which version of MySQL you have as you can use the php_mysql.dll extension on either version of MySQL. You dont need to enable the php_mysqli.dll function if you are using MySQL5.

The thing that sepends on which extension you use is down to the type of mysql functions you are using For example if you are using the mysql_connect function to connect to MySQL or any other mysql_*() function you use the php_mysql.dll extension.
But if you are using the mysqli_connect (note the i after mysql) function to connect to MySQL or any other mysqli_*() function then you use the php_mysqli.dll extension.

#29 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 17 August 2006 - 05:04 PM

It worked! Thank you so much!

#30 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 12 September 2006 - 06:26 PM

For people trying to enable the new MySQL Improved extension on windows:

extension=php_mysqli.dll

Simple as that.

#31 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 16 October 2006 - 05:24 AM

RESOLVED

Yet again...I had to reformat my hard drive and now I get to do all of this all over again...

I'm getting a "Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\emerge\ContactList.php on line 134" again...

php.ini is as follows...

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues.  The alternate is to use the
; cgi.force_redirect configuration below
doc_root =C:\inetpub\wwwroot\

; The directory under which PHP opens the script using /~username used only
; if nonempty.
user_dir =

; Directory in which the loadable extensions (modules) reside.
extension_dir = C:\php\ext

; Whether or not to enable the dl() function.  The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
enable_dl = Off

;;;;;;;;;;;;;;;;;;
;dynamic extentions
;;;;;;;;;;;;;;;;;;

extension=php_mysql.dll

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent).  -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect().  If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

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

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host = localhost

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =localhost

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =dsartain

; Maximum time (in secondes) for connect timeout. -1 means no limit
mysql.connect_timeout = 5000

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off


The php_mysql.dll and the libmysql.dll file is in the C:\php and C:\php\ext directories.  libmysql.dll is also in the C:\WINNT (running Win2K) directory.  I've restarted my IIS (version 4) server and still get the error...What am I missing???

Sorry to post this issue again...

EDIT::I fixed this.  I hadn't added the PHPRC=C:\php to the environment variables for Win2K...thanks though...

#32 Shears

Shears
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 07 January 2007 - 01:47 AM

I have this problem: Cannot load mysql extension. Please check your PHP configuration. - Documentation

The extension_dir in phpinfo shows c:\php5, yet i definetely have extension_dir set to c:\php\ext in the php.ini file. What am i doing wrong?

Despite php.ini being in c:\php, in phpinfo() it says: Configuration File (php.ini) Path C:\WINDOWS - I dont understand this either. Can someone help please...

Thank you

Shears :)


#33 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 07 January 2007 - 06:30 AM

Do you have the php.ini file in more than one place on your HD?  Have you added the directory where your php.ini file is located (i.e. C:\php) to your Windows Path??  If you installed PHP5, are you sure the directory isn't C:\php5 instead of C:\php??  If this doesn't help, please copy and paste your php.ini content as a quote so we can look at it...maybe something is commented out or something.

#34 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 January 2007 - 01:29 PM

I have this problem: Cannot load mysql extension. Please check your PHP configuration. - Documentation

The extension_dir in phpinfo shows c:\php5, yet i definetely have extension_dir set to c:\php\ext in the php.ini file. What am i doing wrong?

Despite php.ini being in c:\php, in phpinfo() it says: Configuration File (php.ini) Path C:\WINDOWS - I dont understand this either. Can someone help please...

Thank you

Shears :)

Its because PHP cannot find the php.ini

PHP looks in the following places for the php.ini
- C:/WINDOWS or C:/WINDOWS/SYSTEM32
- Or in the Windows PATH variable

I would recommend you to add PHP to PATH.

#35 Shears

Shears
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 07 January 2007 - 08:03 PM

Hello .Thank you for your replies :)

Do you have the php.ini file in more than one place on your HD?  Have you added the directory where your php.ini file is located (i.e. C:\php) to your Windows Path??

If you mean, have i entered it in Environmental Variables > System Variables, yes i have.

If you installed PHP5, are you sure the directory isn't C:\php5 instead of C:\php??

I have checked this about 100 times, but i guess it can hurt check another... Ok, yes it is definetely C:\php.

If this doesn't help, please copy and paste your php.ini content as a quote so we can look at it...maybe something is commented out or something.



#36 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 January 2007 - 07:44 PM

Please attach the php.ini to your post. You can do this by doing the following:
Click the Modify button for your post above this.

Expand the Additional Options area. Now attahc your php.ini file to the post. Click Save button. php.ini should now be attached to your post.

Also when you added PHP to the path you did restart your PC? You must restart your PC in order for the changes to the PATH to be made.

#37 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 January 2007 - 10:45 AM

One other thing, you have to create a new Environment Variable called PHPRC, see the php documentation to find the appropriate value, mine is "C:\php"  PHP documentation is located http://www.php.net/manual/en/  So you may want to ensure that you've followed all of the steps precisely.

Also, if you haven't already, you need to make some modifications to IIS (or Apache) to run PHP as well, consult the php documentation for instructions on that as well.

Let me know if you need anything else...

#38 aung

aung
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 March 2008 - 03:37 AM

Hello,

I installed My SQL version 5.0.51a (msi) and PHP version 5.2.5 (msi). But when I run the script, the error message saying that there is no "My SQL extensions".

In fact, when I installed PHP, I selected to install My SQL extensions. Please note that I installed by msi installer package.

PHP.ini include for My SQL extensions. Please see the followings.

[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll

php_mysql.dll is located at C:\PHP\ext.

libmysql.dll is located at C:\PHP

C:\PHP is also in the PATH.

But it didn't work. After reading this forum, I moved "php.ini" to C:\Windows directory and "phpinfo()" now include the section for "My SQL".

Again I tried to run the script below and it return "Unable to connect to MySQL".

Could you advice on that?


<?php
$username = "pee_wee";
$password = "let_me_in";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon
mysql_close($dbh);
?>

Thanks.

Tin Aung Soe

#39 PFMaBiSmAd

PFMaBiSmAd
  • Staff Alumni
  • Advanced Member
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 07 March 2008 - 03:47 AM

Change your or die() statement to the following to get mysql to tell you why the connection failed -

or die("Unable to connect to MySQL: " . mysql_error());

Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#40 dsartain

dsartain
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 07 March 2008 - 04:06 AM

Make sure you've created a new path for PHPRC in the environment variables...look at the first couple of postings and you should see the value of PHPRC.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users