Home >Backend Development >PHP Tutorial >PHP connection database query data
This article mainly shares with you how to query data using PHP to connect to the database, mainly using code methods. I hope it can help everyone.
header("Access-Control-Allow-Origin: *"); header("Control-type:application/json;charset='utf-8'"); $con = mysql_connect('url','username','pwd'); $mysql_db = mysql_select_db('npi',$con) or die ('连接失败'.mysql_errno); mysql_query("set names 'uft8'"); $sql = "select lineno from lineno6s"; $query = mysql_query($sql); if($query&&mysql_num_rows($query)){ while ($row = mysql_fetch_assoc($query)) { $data [] = $row; } } else if(mysql_num_rows($query)==null){ $data = '{content:"blank"}'; echo $data; return; } $jsondata = json_encode($data,JSON_UNESCAPED_UNICODE); echo $jsondata; mysql_close(); exit();
Related recommendations:
How to use PHP to connect to the database to implement the message board function
Use PHP to connect to the database to implement the message board function
The above is the detailed content of PHP connection database query data. For more information, please follow other related articles on the PHP Chinese website!