News

Use PHP Database Connectivity to connect MySQL

PHP is an open-source server scripting language. It is typically used in conjunction with database systems such as MySQL, which provides the back-end database functionality for database-driven websites. MySQL is a free database application that is used extensively with PHP-based Web application systems. To connect to a MySQL database, you need to use the PHP Open Database Connectivity (ODBC) function "odbc_connect" within specific syntax.

 

    • 1. Launch Microsoft Windows Notepad, and open your PHP database configuration file, which might be "config.php" or "db.php," for example.

    • 2. Copy and paste the following PHP source code to connect to your MySQL database:

      <?php

      $dbase_host = "YOUR_HOST";

      $dbase_user = "YOUR_USER_NAME";

      $dbase_pass = "YOUR_DATABASE_PASSWORD";

      $dsn = "DRIVER={MySQL ODBC 3.51 Driver};" .

      "CommLinks=tcpip(Host=$dbase_host);" .

      "DatabaseName=$dbase_name;" .

      "uid=$dbase_user; pwd=$dbase_pass";

      odbc_connect($dsn, $dbase_user, $dbase_pass);

      ?>

      Replace "YOUR_HOST" with the correct host, which is typically "localhost." If you're connecting to a database via an online Web hosting company, confirm the MySQL server host name with the company. Replace "YOUR_USER_NAME" with the user name of your database, and replace "YOUR_DATABASE_PASSWORD" with the password of your database.


    • 3. Press the "Ctrl" + "S" keys on your keyboard to save the file.

    • 4. Exit Notepad.


Versi cetak

Direkomendasikan


Tentang KLATENWEB

Jasa pembuatan aplikasi web berbasis PHP dan MySQL, Web Portal, Personal, Toko Online, Sistem Informasi Akademik, SIMPeg dan Rumah Sakit, Aplikasi Facebook, dan lain sebagainya termasuk penyedia domain dan hosting unlimited murah.