Jump to content


Photo

mysql_connect problems


  • Please log in to reply
13 replies to this topic

#1 mikeymizrahi

mikeymizrahi
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBrooklyn, NY, USA

Posted 14 July 2006 - 02:03 PM

I'm new to mysql and am kind of familiar with PHP.
When trying to connect to mysql through php, i get the following error message:

"Fatal error: Call to undefined function mysql_connect() in C:\www\s.php on line 6"

line 6 reads

"$db = mysql_connect("localhost","root","mypasswordhere");"

i have tried different variations of this line like $con.

i can connect to the db on the mysql command line (no php involved).

where is my problem?

site is: http://mizrahi.ath.cx:8080/php/s.php

thanks,
mikey

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 14 July 2006 - 02:06 PM

<?php

session_start();

$database_host = "localhost";
$database_username = "";
$database_password = "";
$database_name = "";

$connection = mysql_connect($database_host, $database_username, $database_password) or die(mysql_error());
$db = mysql_select_db($database_name, $connection);

?>

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 14 July 2006 - 02:06 PM

i have this in connection.php and then i use

include('connection.php');

in the files i need it in.

hope this helps

#4 wildteen88

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

Posted 14 July 2006 - 02:41 PM

Please read this thread. You need to enable the mysql extension for PHP5

#5 mikeymizrahi

mikeymizrahi
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBrooklyn, NY, USA

Posted 14 July 2006 - 02:43 PM

i get the same error-

maybe i have my username, password, host or database name wrong?

#6 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 14 July 2006 - 02:44 PM

post the full code u are trying to run?

#7 mikeymizrahi

mikeymizrahi
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBrooklyn, NY, USA

Posted 14 July 2006 - 02:54 PM

i tried both this one:

<html>
<body>

<?php

$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

?>

</body>
</html>


and this one as connection.php, like you suggested



<?php

session_start();

$database_host = "localhost";
$database_username = "root";
$database_password = "password";
$database_name = "";

$connection = mysql_connect($database_host, $database_username, $database_password) or die(mysql_error());
$db = mysql_select_db($database_name, $connection);

?>


neither worked, both gave the same error message- where can i go to find my username, host and other info

#8 wildteen88

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

Posted 14 July 2006 - 02:57 PM

mikeymizrahi are you geting an undefined function error message for mysql_connect? If you are need to enable the mysql extension! The version of PHP which you are using is PHP5. PHP5 doesnt come with mysql support builtin, like PHP4 does. So in order you to use the mysql functions you need to enable the mysql extension. In order to enable the mysql extension please click here

#9 mikeymizrahi

mikeymizrahi
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBrooklyn, NY, USA

Posted 14 July 2006 - 03:00 PM

already did that! didnt work

#10 wildteen88

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

Posted 14 July 2006 - 03:02 PM

OKay did you restart your server. Also how is your server setup. There is nothing wrong with your code. The problem is to do with PHP not loading the mysql extension. Could you provide a phpinfo page so I can see your servers configuration.

#11 mikeymizrahi

mikeymizrahi
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBrooklyn, NY, USA

Posted 14 July 2006 - 03:10 PM

yeah, the php info page is at

http://mizrahi.ath.cx:8080/php/php.php

#12 wildteen88

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

Posted 14 July 2006 - 03:15 PM

Okay. Looking at your php.ini. PHP appears to be using the correct ini file. Now the only possible reasons why PHP is unable to load the mysql extension is either of the following:
- a file called libmysql.dll cannot be found, this file is required in order for the mysql extension to function correctyly. See if you can find libmysql.dll within your php folder. If it is, copy this file to your WINDOWS folder. Restart Apache. Is the mysql extension loaded?
- PHP has found an older version of libmysql with is not compatible with your version of PHP. Replace this file with the one in your php folder.

#13 mikeymizrahi

mikeymizrahi
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBrooklyn, NY, USA

Posted 14 July 2006 - 03:19 PM

Working!
The libmysql.dll file was in the PHP folder. I copied it, and it worked!
Thank you VERY much!

--
mikey

#14 wildteen88

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

Posted 14 July 2006 - 03:20 PM

No problem! Glad you got everything up an running.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users