1

Im trying to connect a PHP-Script with an Database. But im Always getting the same Error.

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\Datenbank\login.php:12 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Datenbank\login.php on line 12

This Error happens cuz of line 12.

$connect = mysql_connect("localhost","root","");

But what I made wrong?

Thank you for your help.

iainn
  • 16,011
  • 9
  • 29
  • 38
Venjox
  • 11
  • 1

4 Answers4

0

Fatal error: Uncaught Error: Call to undefined function mysql_connect()

Possibly is this the error. Check the PHP version you are using.

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 and related FAQ for more information. Alternatives to this function include:

mysqli_connect()
PDO::__construct()

http://php.net/manual/en/function.mysql-connect.php

0

This is related to the Php.ini configuration

open the c:\xampp\php\php.ini in a text editor, that locate the line ;extension=php_mysql.dll

Remove the ; at the start, then save the php.ini and restart the xampp server (Apache and MySQL)

0

First of all check your PHP version as in PHP 7 mysql_* functions have been removed.

You can use mysqli_connect instead :

    <?php
        try{
        $host="localhost";
        $user="user";
        $password="pass";
        $databaseName = "myDB";
        $connect=mysqli_connect($host,$user,$password, $databaseName);
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }
        echo "connected succesfully";
        }catch(Exception $e){
        echo $e->getMessage();
        }
    ?>
Kawaljeet Singh
  • 357
  • 1
  • 5
  • Tryd it with your code but im getting now a permissions error, Warning: mysqli_connect(): (HY000/1045): Access denied for user 'Admin'@'localhost' (using password: YES) in C:\xampp\htdocs\Datenbank\login.php on line 46 Failed to connect to MySQL: Access denied for user 'Admin'@'localhost' (using password: YES)connected succesfully – Venjox May 20 '18 at 09:08
0

please try below to see if the PHP MySQL extension module is being loaded::

<?php
    phpinfo();
 ?>
 If it's not there, add the following to the php.ini file:

 extension=php_mysql.dll
Therichpost
  • 1,711
  • 2
  • 14
  • 18