Jump to content


Photo

mysql_connect not working


  • Please log in to reply
2 replies to this topic

#1 kelloggs

kelloggs
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 July 2006 - 10:36 AM

I have installed Apache 2.058, PHP 5.1.4 and MySQL 5.0.22 on my windows server and everything seems to be running as it should, but there is one problem, when I use mysql_connect I get the error:

Fatal error: Call to undefined function mysql_connect() in C:\web\test2.php on line 5

The code:
[pre]<?
$user="root";
$password="pass";
$database="phpbase";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="select * from phptabel";
mysql_query($query);
mysql_close();
?>[/pre]

If I do this it works:

[pre]<?

$mysqli = new mysqli('localhost','root','pass');
$mysqli->select_db('phpbase');

$result = $mysqli->query("SELECT * from phptabel");

while($row = $result->fetch_assoc()) {
print $row['fornavn'] . ' ' . $row['efternavn'] . '<br/>';
}

$result->close();

?>[/pre]
Why can I not use mysql_connect ?

#2 wildteen88

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

Posted 27 July 2006 - 10:39 AM

This becuase PHP5 doesnt come with built in support for MySQL as PHP4 does. Instead you'll need to enable the mysql extension. Please read this tread

#3 kelloggs

kelloggs
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 July 2006 - 11:42 AM

;D

I was missing "extension=php_mysql.dll".

Thx. for the help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users