MariaDB - PHP Syntax



MariaDB partners well with a wide variety of programming languages and frameworks such as PHP, C#, JavaScript, Ruby on Rails, Django, and more. PHP remains the most popular of all available languages due to its simplicity and historical footprint. This guide will focus on PHP partnered with MariaDB.

PHP provides a selection of functions for working with the MySQL database. These functions perform tasks like accessing it or performing operations, and they are fully compatible with MariaDB. Simply call these functions as you would call any other PHP function.

The PHP functions you will use for MariaDB conform to the following format −

mysql_function(value,value,...);

The second part of the function specifies its action. Two of the functions used in this guide are as follows −

mysqli_connect($connect);
mysqli_query($connect,"SQL statement");

The following example demonstrates the general syntax of a PHP call to a MariaDB function −

<html>
   <head>
      <title>PHP and MariaDB</title>
   </head>

   <body>
      <?php
         $retval = mysql_function(value, [value,...]);
      
         if( !$retval ) {
            die ( "Error: Error message here" );
         }
         // MariaDB or PHP Statements
      ?>
   </body>
</html>

In the next section, we will examine essential MariaDB tasks, using PHP functions.

Advertisements