-1

i am using xampp this is my application_top file when i run script is show that issue anyone help me to solve that issue


    <?php

    include('config.php');
    include('functions.php');

    // Connect to database
    $dbConnection = mysql_pconnect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error(),E_USER_ERROR); 

    mysql_select_db(DB_NAME, $dbconn);

    ?>

this is my config file


    <?php

    // Database Settings
    define('DATABASE_HOST','localhost'); // Hostname of database server. Usually 'localhost'
    define('DATABASE_NAME','script'); // The name of the database to connect to
    define('DATABASE_USER','root'); // The username to connect to the database as
    define('DATABASE_PASS',''); // The password to use on the database
    ?>


  • 2
    The `die()` function only takes 1 parameter. – Nigel Ren Dec 23 '19 at 14:43
  • when i do `die(mysql_error(),E_USER_ERROR)` to `die()` i got that error `Fatal error: Uncaught Error: Call to undefined function mysql_pconnect() in C:\xampp\htdocs\script\includes\application_top.php:7 Stack trace: #0 C:\xampp\htdocs\script\index.php(2): include() #1 {main} thrown in C:\xampp\htdocs\script\includes\application_top.php on line 7` – Muhammad Muneeb Ahmad Dec 23 '19 at 14:48
  • 2
    That is the second duplicate - `mysql_` has been removed from PHP. – Nigel Ren Dec 23 '19 at 14:53
  • You have defined different variable and put another variable... I would like to recommend using ```mysqli``` instead – Biplove Lamichhane Dec 23 '19 at 14:56
  • If you're writing new code, **_please_, for the love of all you hold dear, don't use the `mysql_*` functions!** They are old and broken, were deprecated in PHP 5.5, and completely removed in PHP 7.0 (which is so old it [no longer even receives active support](http://php.net/supported-versions.php)). Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. It's _2019_. This isn't funny anymore. – ChrisGPT was on strike Dec 23 '19 at 16:28

1 Answers1

-1

Check it:

<?php

    include('config.php');
    include('functions.php');

    // Connect to database
    $dbConnection = mysql_pconnect(DB_HOST, DB_USER, DB_PASS);

    if (! $dbConnection) {
        die(mysql_error());
    }

    $db_selected = mysql_select_db(DB_NAME, $dbConnection);

    if (!$db_selected) {
        die ('Can\t use: ' . mysql_error());
    }

?>
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42