1. Execute SQL statements in PHP
To get data from a database, first PHP executes a SQL statement that operates on a table, including a SELECT, INSERT, UPDATE, or DELETE statement. In general, executing a SELECT statement in PHP will find some record rows from the table. Execution of other statements will only return information about whether the statement executed successfully.
Success ';
$num =mysql_num_rows ($result);//Get the number of rows of the query's results
Echo '
'. $num. ' Rows ';
}
Mysql_close ($conn);
? >
Typically, mysql_query () is also used with mysql_error () to find the cause of the problem, depending on the information generated by mysql_error () when there is a problem with the SQL statement execution.
ERROR:". Mysql_error ()."
Problem:
. $sql ");
if ($result)
{
echo ' Sqlsyntex: '. $sql. '
Success ';
$num =mysql_num_rows ($result);
Echo '
'. $num. ' Rows ';
}
Mysql_close ($conn);
? >
2. Processing the data result set in PHP
When an SQL statement is successfully executed in a program, you can use Mysql_fetch_array () to obtain a specific query result that uses this function to get the field value of the record.
-->ERROR:". Mysql_error ()."
Problem:
. $sql ");
if ($num =mysql_num_rows ($result)) {$row =mysql_fetch_array ($result); Echo '';
Print_r ($row);
Mysql_close ($conn);
? >
function mysql_fetch_array (), which tells you that the function returns a row in the result set, as an associative or normal array, and that the return array is both available by default. The array returned by Mysql_fetch_array () establishes two indexes for each field value: One is indexed numerically and the other is indexed by field names. ERROR: ". Mysql_error (). "
Problem:
. $sql "); if ($num =mysql_num_rows ($result)) {$row =mysql_fetch_array ($result);
Echo '