Your cart is currently empty!
Category: mariadb
-
Khóa học miễn phí MariaDB – Connection nhận dự án làm có lương
MariaDB – Connection
One way to establish a connection with MariaDB consists of using the mysql binary at the command prompt.
MYSQL Binary
Review an example given below.
[root@host]# mysql -u root -p Enter password:******
The code given above connects to MariaDB and provides a command prompt for executing SQL commands. After entering the code, a welcome message should appear indicating a successful connection, with the version number displayed.
Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 122323232 Server version: 5.5.40-MariaDB-log Type ''help;'' or ''h'' for help. Type ''c'' to clear the current input statement. mysql>
The example uses root access, but any user with privileges can of course access the MariaDB prompt and perform operations.
Disconnect from MariaDB through the exit command as follows −
mysql> exit
PHP Connection Script
Another way to connect to and disconnect from MariaDB consists of employing a PHP script. PHP provides the mysql_connect() function for opening a database connection. It uses five optional parameters, and returns a MariaDB link identifier after a successful connection, or a false on unsuccessful connection. It also provides the mysql_close() function for closing database connections, which uses a single parameter.
Syntax
Review the following PHP connection script syntax −
connection mysql_connect(server,user,passwd,new_link,client_flag);
The description of the parameters is given below −
Sr.No Parameter & Description 1 server
This optional parameter specifies the host name running the database server. Its default value is “localhost:.3036.”
2 user
This optional parameter specifies the username accessing the database. Its default value is the owner of the server.
3 passwd
This optional parameter specifies the user”s password. Its default value is blank.
4 new_link
This optional parameter specifies that on a second call to mysql_connect() with identical arguments, rather than a new connection, the identifier of the current connection will be returned.
5 client flags
This optional parameter uses a combination of the following constant values −
-
MYSQL_CLIENT_SSL − It uses ssl encryption.
-
MYSQL_CLIENT_COMPRESS − It uses compression protocol.
-
MYSQL_CLIENT_IGNORE_SPACE − It permits space after function names.
-
MYSQL_CLIENT_INTERACTIVE − It permits interactive timeout seconds of inactivity prior to closing the connection.
Review the PHP disconnection script syntax given below −
bool mysql_close ( resource $link_identifier );
If you omit the resource, the most recent opened resource will close. It returns a value of true on a successful close, or false.
Try the following example code to connect with a MariaDB server −
<html> <head> <title>Connect to MariaDB Server</title> </head> <body> <?php $dbhost = ''localhost:3036 $dbuser = ''guest1 $dbpass = ''guest1a $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die(''Could not connect: '' . mysql_error()); } echo ''Connected successfully mysql_close($conn); ?> </body> </html>
On successful connection, you will see the following output −
mysql> Connected successfully
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc
-
Khóa học miễn phí MariaDB – PHP Syntax nhận dự án làm có lương
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.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc