Take the following code query as an example
<?phpheader ("content-type:text/html; Charset=utf-8 "); $host = "localhost"; $user = "root"; $password = "root"; $dbase _name= "Liuyan"; $table _name= "Contents"; $conn =mysql_ Connect ($host, $user, $password) or Die ("Connection server failed. ". Mysql_error ()); echo" Database server: $host user name: $user <br> "; echo" ...................................................<br> "; mysql_select_db ($dbase _name, $conn) or Die (" Failed to connect to database ". Mysql_error ()); echo" Database name: ". $dbase _name.", Data table name: ". $table _name." <br> "; mysql_query (" SET NAMES ' UTF8 ' "); $mysql _command=" select * from ". $table _name." where id=5 "; $result =mysql_query ($mysql _command, $conn) or Die (" <br> data Sheet no record <br> "); $i =0;while ($record = Mysql_fetch_row ($result)) {$i +=1;echo "ID Number:" $record [0]. " <br> "; echo" Name: ". $record [1]." <br> "; echo" Content: ". $record [2]." <br> "; echo" ...................................................<br> ";} echo "successfully displayed the datasheet". $table _name. " Records, the number of records is: ". $i;
Tips are as follows:
However, there is data in the data table, it is a long time to find the most common error when stitching SQL statements forget to add a space, the code to:
$mysql _command= "SELECT * from" $table _name. "Where id=5";
then runs through.
SQL error not found for beginners to die