Jump to content

Archived

This topic is now archived and is closed to further replies.

mikeymizrahi

mysql_connect problems

Recommended Posts

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

Share this post


Link to post
Share on other sites
<?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);

?>

Share this post


Link to post
Share on other sites
i have this in connection.php and then i use

include('connection.php');

in the files i need it in.

hope this helps

Share this post


Link to post
Share on other sites
Please [url=http://www.phpfreaks.com/forums/index.php/topic,95378.0.html]read this thread[/url]. You need to enable the mysql extension for PHP5

Share this post


Link to post
Share on other sites
i tried both this one:

[color=blue]<html>
<body>

<?php

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

?>

</body>
</html>
[/color]

and this one as connection.php, like you suggested

[color=red]

<?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);

?>
[/color]

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

Share this post


Link to post
Share on other sites
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 [url=http://www.phpfreaks.com/forums/index.php/topic,95378.0.html]click here[/url]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Working!
The libmysql.dll file was in the PHP folder. I copied it, and it worked!
Thank you VERY much!

--
mikey

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.