MySQL Error

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1391 Views - Last Post: 09 September 2010 - 04:49 PM Rate Topic: -----

#1 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

MySQL Error

Posted 07 September 2010 - 05:47 PM

Okay, I had tried to use Apache but I couldn't figure it out on Windows 7 so I'm using IIS with PHP and MySQL installed. For some reason when I try to use PHP to access MySQL I get this and I don't know why
PHP Fatal error:  Call to undefined function mysql_connect() in D:\www\index.php on line 33


I have everything installed and my php.ini file is setup for MySQL to work. If you got any input that'd be great!

Another thing, how can I configure SQL Server to work with PHP too?

Thanks,
Daniel

Is This A Good Question/Topic? 0
  • +

Replies To: MySQL Error

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10567
  • View blog
  • Posts: 39,123
  • Joined: 27-December 08

Re: MySQL Error

Posted 07 September 2010 - 05:51 PM

Could you post your code as well? Perhaps you aren't passing the correct or enough parameters?
Was This Post Helpful? 0
  • +
  • -

#3 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: MySQL Error

Posted 07 September 2010 - 06:01 PM

Yeah sure, heres my code or the MySQL connection part anyway
	$link = mysql_connect('localhost', 'root', 'password');
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db('localhost');
	if(!$db) {
		die("Unable to select database");
	}


Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Re: MySQL Error

Posted 07 September 2010 - 06:48 PM

Your php.ini configuration is wrong. It's not loading the mysql DLL.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: MySQL Error

Posted 07 September 2010 - 10:43 PM

check in the phpinfo(), what db drivers are available (mysqli, PDO, etc.)
Was This Post Helpful? 1
  • +
  • -

#6 ludo237  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: -1
  • View blog
  • Posts: 21
  • Joined: 04-September 10

Re: MySQL Error

Posted 08 September 2010 - 03:54 AM

View Postdanielair, on 07 September 2010 - 05:01 PM, said:

Yeah sure, heres my code or the MySQL connection part anyway
	$link = mysql_connect('localhost', 'root', 'password');
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db('localhost');
	if(!$db) {
		die("Unable to select database");
	}


are you sure that root & password are the correct username and password?
Was This Post Helpful? 0
  • +
  • -

#7 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: MySQL Error

Posted 08 September 2010 - 02:15 PM

View Postludo237, on 08 September 2010 - 06:54 AM, said:

are you sure that root & password are the correct username and password?


Incorrect credentials wouldn't cause PHP to see the function as undefined. Undefined functions result from the extension (or file, if it's user-defined) containing the function definition(s) not being loaded.
Was This Post Helpful? 0
  • +
  • -

#8 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: MySQL Error

Posted 09 September 2010 - 02:48 PM

I'm sure the credentials are correct though. And here is what the extension section looks like:
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_exif.dll
;extension=php_fileinfo.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_ming.dll
;extension=php_mssql.dll
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll  ; Use with Oracle 11g Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_phar.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll



Daniel
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Re: MySQL Error

Posted 09 September 2010 - 03:12 PM

Are you sure the INI file you've printed is the one in use by PHP? I don't know much about PHP and IIS (this site might be helpful), but perhaps you need to stop/restart IIS?
Was This Post Helpful? 0
  • +
  • -

#10 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: MySQL Error

Posted 09 September 2010 - 03:32 PM

Ok I fixed one problem, the extension wasn't set correctly but thats fixed now. But Now theres a new problem that I still don't understand, when I run my script I get this

PHP Warning:  mysql_connect(): [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in D:\www\index.php on line 33
PHP Warning:  mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
 in D:\www\index.php on line 33
PHP Fatal error:  Maximum execution time of 30 seconds exceeded in D:\www\index.php on line 33



Daniel
Was This Post Helpful? 0
  • +
  • -

#11 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: MySQL Error

Posted 09 September 2010 - 03:40 PM

Check to see whether MySQL is reachable from GUI tools or via the command line. If you can connect there, change localhost to 127.0.0.1. Some IIS users have reported that as a common problem when dealing with PHP connecting to MySQL.
Was This Post Helpful? 0
  • +
  • -

#12 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: MySQL Error

Posted 09 September 2010 - 03:57 PM

View PostValek, on 09 September 2010 - 02:40 PM, said:

Check to see whether MySQL is reachable from GUI tools or via the command line. If you can connect there, change localhost to 127.0.0.1. Some IIS users have reported that as a common problem when dealing with PHP connecting to MySQL.


Ok I can access it from the command line, but when I try to run it with phpMyAdmin I get a 500 error. Do you mean change the url in the browser from "localhost" to "127.0.0.1" (that had no affect) or in the MySQL settings. If you mean the MySQL setting could you explain how to do this?

Thanks,
Daniel
Was This Post Helpful? 0
  • +
  • -

#13 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: MySQL Error

Posted 09 September 2010 - 04:22 PM

Ok I figured out what you meant. I changed my phpMyAdmin configuration to connect with 127.0.0.1 instead of localhost, but how can I make it so that I can connect on localhost so I wouldn't have to change all my scripts?

Thanks,
Daniel
Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Re: MySQL Error

Posted 09 September 2010 - 04:34 PM

Google Windows 7 localhost
Was This Post Helpful? 1
  • +
  • -

#15 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: MySQL Error

Posted 09 September 2010 - 04:40 PM

Try adding 127.0.0.1 localhost to your hosts file. (It's hidden under C:\Windows\System32\drivers\etc\)

I ran across this same problem in the Win7 beta, but not since then. The problem was that Win7 didn't associate "localhost" with the IPv4 loopback (127.0.0.1) but only the IPv6 loopback (::1). Adding it manually fixed it back then.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2