Home  >  Article  >  Backend Development  >  PHP connection database query data

PHP connection database query data

小云云
小云云Original
2018-03-22 11:39:206265browse

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

php connects to the database to implement the addition, deletion, modification and query of user data.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn