Page 1 of 1

mysql_connect();

Posted: Sun Oct 23, 2005 2:19 pm
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]

Posted: Sun Oct 23, 2005 3:13 pm
by Ree

Posted: Sun Oct 23, 2005 5:59 pm
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.

Posted: Sun Oct 23, 2005 7:40 pm
by John Cartwright
viewtopic.php?t=39785
.................

Posted: Sun Oct 23, 2005 9:05 pm
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

Posted: Sun Oct 23, 2005 9:25 pm
by feyd
you're "missing" a library essential to mysql's client operations, like libmysql.dll, in your path.

Posted: Sun Oct 23, 2005 10:37 pm
by FREESTYLER
find the libmysql.dll and copy it to your windows system32 directory

Posted: Mon Oct 24, 2005 6:53 am
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

Posted: Mon Oct 24, 2005 7:14 am
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.

Posted: Mon Oct 24, 2005 11:07 pm
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.

Posted: Mon Oct 24, 2005 11:08 pm
by ihatemash
oops, I forgot to add that the error msgs. say "Access is denied".

Posted: Tue Oct 25, 2005 12:06 am
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]

Posted: Tue Oct 25, 2005 12:11 am
by Jenk
That's due to the changes in mysql password encryption.

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

Posted: Tue Oct 25, 2005 7:50 am
by ihatemash
WOW..... IT WORKS.....

Thanks for all the help.

Posted: Tue Oct 25, 2005 8:06 am
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