PHP connection database query data

小云云
Release: 2023-03-21 22:50:01
Original
6392 people have browsed it

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template