0% found this document useful (0 votes)
137 views2 pages

Mysql - PHP Syntax: Mysql - Function (Value, Value,... )

This document provides an overview of connecting to a MySQL database from PHP. It explains that PHP functions allow accessing and manipulating MySQL data, and lists some common functions like mysqli_connect() and mysqli_query(). It also shows a generic PHP syntax for calling MySQL functions and handling errors. The document then shifts to discussing connecting to MySQL directly from the command line using the mysql binary.

Uploaded by

Fetsum Lakew
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
137 views2 pages

Mysql - PHP Syntax: Mysql - Function (Value, Value,... )

This document provides an overview of connecting to a MySQL database from PHP. It explains that PHP functions allow accessing and manipulating MySQL data, and lists some common functions like mysqli_connect() and mysqli_query(). It also shows a generic PHP syntax for calling MySQL functions and handling errors. The document then shifts to discussing connecting to MySQL directly from the command line using the mysql binary.

Uploaded by

Fetsum Lakew
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

MySQL - PHP Syntax

MySQL works very well in combination of various programming languages like PERL,
C, C++, JAVA and PHP. Out of these languages, PHP is the most popular one
because of its web application development capabilities.

This tutorial focuses heavily on using MySQL in a PHP environment. If you are
interested in MySQL with PERL, then you can consider reading the PERL Tutorial.

PHP provides various functions to access the MySQL database and to manipulate the
data records inside the MySQL database. You would require to call the PHP functions
in the same way you call any other PHP function.

The PHP functions for use with MySQL have the following general format −
mysql_function(value,value,...);

The second part of the function name is specific to the function, usually a word that
describes what the function does. The following are two of the functions, which we will
use in our tutorial −
mysqli_connect($connect);
mysqli_query($connect,"SQL statement");

The following example shows a generic syntax of PHP to call any MySQL function.
<html>
<head>
<title>PHP with MySQL</title>
</head>

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

Starting from the next chapter, we will see all the important MySQL functionality along
with PHP.

MySQL - Connection
MySQL Connection Using MySQL Binary
You can establish the MySQL database using the mysql binary at the command
prompt.

Example

Here is a simple example to connect to the MySQL server from the command prompt −
[root@host]# mysql -u root -p
Enter password:******

This will give you the mysql> command prompt where you will be able to execute any
SQL command. Following is the result of above command −

The following code block shows the result of above code −


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2854760 to server version: 5.0.9

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

In the above example, we have used root as a user but you can use any other user as
well. Any user will be able to perform all the SQL operations, which are allowed to that
user.

You can disconnect from the MySQL database any time using the exit command at
mysql> prompt.
mysql> exit
Bye

You might also like