-2

I am using the below code

$con = @mysql_connect($this->host, $this->user, $this->password); 

While following code is working fine.

$con = mysqli_connect("localhost","root","");

my php version is 5.5.33,what is the problem?

user94
  • 409
  • 1
  • 6
  • 20
  • Shouldn't matter, mysql_* is deprecated, you need to use mysqli_* functions, or PDO. – Enstage May 25 '17 at 05:20
  • 1
    @user94 Is there any error , remove @ before mysql_connect and you will get the error . Post error as well . FYI mysql_connect is no longer supported – Deepak Dixit May 25 '17 at 05:29
  • removed @ but unfortunately I will not get any error. – user94 May 25 '17 at 05:38
  • 1
    Make sure you have full error reporting enabled: `error_reporting(E_ALL);`. – Barmar May 25 '17 at 05:39
  • The mysql functions don't usually report errors by themselves, you have to check for them explicitly. `$con = mysql_connect(...) or die(mysql_error());` – Barmar May 25 '17 at 05:42
  • ya I got this error when removing @ "Call to undefined function mysql_connect() in C:\xampp\htdocs\website\_inc\_class\Database.php on line 39".but this all code is perfectly working in live. – user94 May 25 '17 at 05:44
  • did you getting any error? so what is it? – Md. Abutaleb May 25 '17 at 05:46
  • Call to undefined function mysql_connect() in C:\xampp\htdocs\website\_inc\_class\Database.php on line 39 – user94 May 25 '17 at 05:47
  • Then you need to switch to MySQLi or PDO. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 31 '17 at 15:47

2 Answers2

-1

mysql extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

-2

Permanent Solution:You can install xampp with php 5.4. or 5.3 then put your code there.Definetly you not get any error.

I am facing more issue like syntax error or many so i putted my code in 5.4 oh with xampp 1.0.8.Please try This is not my guessing I am putted my code there and i got not any error.

Because:mysql extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.