How to use PHP mysql_query() function

 The mysql_query() function is a commonly used MySQL database syntax in PHP . It is used to determine whether the database query is successful. If the query is successful, it will return true, otherwise it will return false. Generally, it can be used after connecting with the database. Create a database connection first, and it will automatically get a connection through the mysql_connect() function. Of course, this situation is not very good, so it is recommended to confirm your PHP and MySQL connection to establish it correctly. The basic syntax is as follows: mysql_query( string query [, resource connection] ); Among them, string query can be database query, database update or other actions. If it executes successfully, it will return true, no matter if the query account password is wrong, the query specified database is wrong, or the data table If there is an error in the field or other errors, false will be returned. Give a simple example



<?php
 $connect = mysql_connect("localhost","account","password"); //Create a database connection
 $sql = "SELECT * FROM table"; //Search the taqble table
 mysql_query( $sql,$ connect ); //Whether the return of $sql is executed correctly
>
In this example, we first connect to the database, and then write a simple $sql syntax to query the table data table, and finally use the mysql_query() function to determine whether the $sql is executed correctly, and if it is correct, it will return true. There is a problem It returns false.

Post a Comment

0 Comments