Jump to content

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
Link to comment
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);

?>
Link to comment
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
Link to comment
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]
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.