0

I'm running MySQL server version 5.0.77 on Linux (Rocks Cluster Distro), and I'm trying to connect to the same database with both MySQL and MySQLi PHP functions. The problem is that when the MySQLi code fragment is executed it does work, but the MySQL fragment doesn't (in case it matters; not even on separate PHP files).

As shown in the code below I'm attempting a connection to the same database on the same host, using the same user and password but the MySQL function version fails.

(If it helps I've already tried the same code on MySQL server 5.6.20 running in Windows with the same details ((local)host, database, user, password) and both functions work).

What might be the problem? Any help is appreciated.

The output and code fragment is the following:

Code:

<?PHP
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tedDB";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Error [mysqli]: ".$conn->connect_error);
} else {
    echo "Success [mysqli]";
}

echo "<br><br>";

$link = mysql_connect($servername, $username, $password)
    or die("Error [mysql_connect]: ".mysql_error());
echo "Success [mysql_connect]";
?>

Output (LINUX):

Success [mysqli]

Error: Access denied for user 'root'@'localhost' (using password: NO)

Output (Windows):

Success [mysqli]

Success [mysql_connect]
Will Rar
  • 1
  • 1
  • 6
    Why even bother with `mysql_connect` when it’s deprecated? – icktoofay Dec 09 '14 at 00:47
  • 1
    Please do not use the `mysql_*` functions - as @icktoofay point out, they have been deprecated. Consider using PDO instead. – Madbreaks Dec 09 '14 at 00:48
  • I'm aware of that, but it's for a school project and some classmates are too lazy to use mysqli because they learned the mysql_connect-related way. – Will Rar Dec 09 '14 at 00:49
  • If your PHP's 5.5, then `mysql_` will most likely not work. Adding error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Dec 09 '14 at 00:50
  • 4
    Unfortunately for those classmates, it’s going to stop working sooner or later. Maybe sooner has arrived. Lazy? Well, maybe this’ll be the impetus for them to learn a newer interface to MySQL. – icktoofay Dec 09 '14 at 00:52
  • @Fred-ii- "will most likely not work" - the whole point of deprecation is that the functions DO still work... but only for now – rjdown Dec 09 '14 at 00:56
  • 1
    @rjdown Those old functions actually don't work on Wamp server's install. – Funk Forty Niner Dec 09 '14 at 01:14
  • His problem is on nix... windows is fine – rjdown Dec 09 '14 at 01:51

0 Answers0