-1

I have been trying to connect my registrationform with my sql database for a few days now. I've tried to find the issues in my code but eventually I went for a simple check if a connection was possible with the following code:

<?php
define('DB_HOST', '`............');
define('DB_NAME', '.............');
define('DB_USER', '..............');
define('DB_PASSWORD', '..........');

$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) 
    or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";
?>

Which always returns blank. This was equally the issue when I tried to connect my registrationform to the server.

Can someone maybe explain what could be wrong. I checked the DB host, name,username and password, so that can't be the problem.

thanks

Zak.M
  • 1
  • Any errors in the web server log? – Jason K Oct 30 '19 at 21:40
  • 2
    The problem is likely due to the fact that your webserver **does not support PHP 5**. The `mysql_*` functions have been **deprecated since 2013** (in PHP 5.5), and are **removed as of PHP 7.0** (released in 2015). This is because they have **serious** security vulnerabilities. **DO NOT USE THEM**. Please consider upgrading your PHP, and switching to either [**MySQLi**](http://php.net/manual/en/book.mysqli.php) or [**PDO**](http://php.net/manual/en/book.pdo.php) instead. – Obsidian Age Oct 30 '19 at 21:40
  • @ObsidianAge thank you, you were correct. ;) – Zak.M Oct 31 '19 at 19:22

1 Answers1

-2

these days you want to use mysqli like the following (I don't define variables [usr/pass/db/etc] just to then use them so I just put the info directly in the command as below):

    $db = mysqli_connect("localhost", "username", "password", "database");
    if (!$db) {
        echo "Error: Unable to connect to MySQL." . PHP_EOL;
        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
        exit;
    } else {
        echo "Connected to MySQL<br>";
    }
PENDRAGON
  • 91
  • 2
  • 6
  • Please do not suggest such crude code. Check out this article explaining how to do it right: https://phpdelusions.net/mysqli/mysqli_connect – Dharman Oct 30 '19 at 23:00