mysql_connect();

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

mysql_connect();

Post by ihatemash »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I have the following code in my php file:

Code: Select all

$db_hostname = "localhost";  //usually "localhost be default"
$db_username = "myusername";  //your user name
$db_pass = "mypassword";  //the password for your user
$db_name = "mydbname";  //the name of the database

$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


each time this code executes, i get an error "Fatal error: Call to undefined function mysql_connect() in E:\Website\testconnecttion.php on line 6"

What am i doing wrong (i'm very new to PHP).


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ok i should be past the inability to do this too but i just installed php 5 and apache on my labtop today and i tried going through those instructions and it did nothing. anyone have a tutorial that works? maybe some pointers would be helpful.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

viewtopic.php?t=39785
.................
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

Post by ihatemash »

i did that but now i'm getting "PHP Startup: Unable to load dynamic library 'c:\php\php_mysql.dll' - The specified procedure could not be found". I move the DLLs from the ext folder to the C:\PHP folder because i kept getting an error that access was denied when the dll's were in the ext subfolder (not sure why).

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're "missing" a library essential to mysql's client operations, like libmysql.dll, in your path.
FREESTYLER
Forum Newbie
Posts: 17
Joined: Tue Oct 18, 2005 10:33 am

Post by FREESTYLER »

find the libmysql.dll and copy it to your windows system32 directory
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

Post by ihatemash »

Still getting the same thing. i tried c:\windows, c:\windows\system, and c:\windows\system32. i also copied all dll under the c:\php folder to windows, system, and system32. PHP works, i can view PHP pages as long as there is no MySql code. Im doing everything on a stand alone machine. I.e. i'm not browsing accross a network to view the PHP pages.

-scott
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i just got mine working. in your php.ini file search for this line

extension_dir =

set it to the exact location of your PHP folder. (ie. D:\The Folder\The PHP Folder) - in my case.
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

Post by ihatemash »

Ok, I changed the extension_dir to point to the exact path c:\php\ext and now I’m getting an error for both MySQL DLL's "PHP Startup: Unable to load dynamic library 'C:\PHP\EXT\PHP_MYSQL.DLL" and "PHP Startup: Unable to load dynamic library 'C:\PHP\EXT\PHP_MYSQLI.DLL". I'm using IIS not Apache so I changed cgi.force_redirect = 0. The comments in the INI file say to turn it off for IIS. Should I use Apache? I just want to test a website on my local machine. I don't want to test on the live server so I was hoping to do all development on 1 machine which will require the machine to serve the web pages.
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

Post by ihatemash »

oops, I forgot to add that the error msgs. say "Access is denied".
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

Post by ihatemash »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


This sux.... I gave up on PHP 5 and went to an older version and i no longer get the DLL errors. however, when i attempt to connect to the DB, I get...

Client does not support authentication protocol requested by server; consider upgrading MySQL clientPHP Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in E:\Web Sites\phptest\testpage.php on line 19.

MySQL version is 4.1.15-nt and i can connect via MySQL Command Line Client.

here is the full source code for testpage.php:

Code: Select all

<html>
<head>
<title>Test Page</title>
</head>
<body>
<h1>Test page</h1>
<p>Here is the content...</p>
<?php
//Please set the following variables for your mysql database:
$db_hostname = "localhost";  //usually "localhost be default"
$db_username = "root";  //your user name
$db_pass = "sa";  //the password for your user
$db_name = "phpdb";  //the name of the database

/*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
--------------------------------------*/
// connect to database

$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die (mysql_error());
mysql_select_db ($db_name);
?>

</body>
</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

That's due to the changes in mysql password encryption.

http://dev.mysql.com/doc/refman/5.0/en/old-client.html
ihatemash
Forum Newbie
Posts: 7
Joined: Sun Oct 23, 2005 2:10 pm

Post by ihatemash »

WOW..... IT WORKS.....

Thanks for all the help.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i would go with apache instead of IIS, i used to use IIS but had alot of trouble but now that i installed apache it works perfectly, no problems and no maintence
Post Reply