7

hey I am using xampp and trying to run localhost but constantly getting an error in connect.php...error is as follows

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\admin panel\connect.php:9 Stack trace: #0 C:\xampp\htdocs\admin panel\index.php(16): include() #1 {main} thrown in C:\xampp\htdocs\admin panel\connect.php on line 9

my connect.php code is as follows

<?php
$servername = "localhost";
$username = "root";
$password = "";
mysqli_connect($servername,$username,$password) or die('cannot connect to  
the server'); 
?>     

please help me out with this.

Akhter Al Amin
  • 852
  • 1
  • 11
  • 25
Panther
  • 103
  • 6
  • 3
    strange, error says `mysql_connect` and the code has `mysqli_connect`. Both are different functions from different extensions `php_mysql` and `php_mysqli`. Check if these extension are enabled in php.ini. – Jigar Oct 19 '16 at 06:06
  • yes it's strange. Actually `mysql_*` is deprecated from PHP5 and removed from PHP7. So may be somewhere in your code you used `mysql_*` and that's why you get that error. B – Alive to die - Anant Oct 19 '16 at 06:09
  • `$con = mysqli_connect($servername,$username,$password) or die('cannot connect to the server'); if($con){ echo 1; }else{echo 0;}` add this and share the result – devpro Oct 19 '16 at 06:09
  • @devpro its fatal error, script won't go ahead. :) – Jigar Oct 19 '16 at 06:10
  • than chk the answer what he is saying, or also check the version by `php info function` – devpro Oct 19 '16 at 06:11

2 Answers2

0

Uncomment the line extension=php_mysql.dll in your "php.ini" file and restart Apache. if its not working then update your xampp with latest version.

0

Warning This 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. See also MySQL: choosing an API guide. Alternatives to this function include:

mysqli_connect()

PDO::__construct()
use MySQLi or PDO

<?php
$con = mysqli_connect('localhost', 'username', 'password', 'database');

check this "Call to undefined function mysql_connect()" after upgrade to php-7

refer this link for mysqli extension help http://www.w3schools.com/php/func_mysqli_connect.asp

Community
  • 1
  • 1
viral barot
  • 631
  • 4
  • 8