About 2,130,000 results
Open links in new tab
  1. Including database connection file in php - Stack Overflow

    Dec 26, 2013 · As you can see I have included the dbconnection.php file in my login.php but whenever I try to call the authenticate () function, this error is returned: Notice: Undefined variable: db in C:\xampp\htdocs\xxxxxxxx\login.php on line 27. Fatal error: Call to a member function query () on a non-object in C:\xampp\htdocs\xxxxxxx\login.php on line 27.

  2. PHP include and database connection - Stack Overflow

    Aug 1, 2013 · PHP has alternate versions of include() and require() which address this problem. Use include_once() or require_once() for files which might be included from multiple files to prevent the common file from being included in your code multiple times.

  3. How to connect to a database using PHP's include

    Nov 8, 2018 · require_once "configuration.php"; $Conf = new JConfig; // Create connection $conn = mysqli_connect($Conf->host, $Conf->user, $Conf->password, $Conf->db); In simple terms the config file contains an class named JConfig , so you must instantiate that class and access it's public properties.

  4. PHP MySQL Connect to database - W3Schools

    PHP 5 and later can work with a MySQL database using: MySQLi extension (the "i" stands for improved) PDO (PHP Data Objects) Earlier versions of PHP used the MySQL extension. However, this extension was deprecated in 2012.

  5. How to Connect MySQL Database to PHP Using MySQLi and PDO?

    Apr 9, 2025 · To create a MySQL database in Cloudways and connect it to your PHP application, you can SSH into your server or use an FTP client to simply upload your PHP files. For this tutorial, I’ll use the FTP approach.

  6. How to Import config.php File in a PHP Script? | GeeksforGeeks

    Jul 23, 2024 · You can also include connection-building statements in the “config.php” file to automatically establish a database connection for every page that includes “config.php”. Including files allows you to create a template of code that can be reused by multiple pages of a website. include('config.php');

  7. How to connect MySQL Database with PHP Website

    Include the database connection file in your PHP script: In the PHP script that you want to connect to the database, add the following code at the top of the script: include 'db_connection.php'; Use the database connection object to perform database operations: Once you have connected to the database, you can use the $conn object to perform ...

  8. Connecting to a MYSQL database in a seperate file (PHP)

    Feb 23, 2011 · In my guestbook script I need to connect to a database. To make it more secure I want the database login details in a seperate PHP file. This is also handy because these details can be used by other pages. I can't seem to figure it out. Getting a …

  9. How to connect MySQL Database to PHP Website? [Updated Guide] - Brainvire

    Aug 6, 2021 · We’ll begin with a PHP file called ‘DB connection.php.’ S save a different file so that there is no need to write a connection code for each file individually. Instead, users can conveniently include this file in the requisite file by calling it and then using the ‘include’ function.

  10. Using MySQL Connection Code in Multiple PHP Files - ThoughtCo

    Jul 3, 2019 · Put the MySQL connection code in a separate file and then call the saved file where you need it. For example, use the SQL code below in a PHP script to log in to your MySQL database. Save this code in a file called datalogin.php.

Refresh