美文网首页
[笔记]php连接mysql数据库

[笔记]php连接mysql数据库

作者: 巨数 | 来源:发表于2020-08-26 21:47 被阅读0次

php有很多连接mysql数据库的方法, 但是有时会各种失败, 记录一下能成功运行的模板

<?php
  $mysql_server_name="localhost";
  $mysql_username="root";
  $mysql_password="1234";
  $mysql_database="db";
  $conn=new mysqli($mysql_server_name,$mysql_username,$mysql_password);
  $conn->query("set names 'utf8'");
  $conn -> select_db($mysql_database);
  $njn = substr($_POST["id"],0,2);
  $sql = "select * from info where id <> '{$_POST["id"]}'";
  $result1 = $conn->query($sql);
  $data=array();
  echo "<tr class='info'>";
  $num = 0;
  if ($result1->num_rows > 0) {
      while ($tmp=$result1->fetch_assoc())
      {
          if($num%7==0 and $num !=0){
            echo "</tr><tr class='info_tr'>";
          }
          echo "<td><a href='index.php?id={$tmp["id"]}'> {$tmp['sname']} </a></td>";
          $num += 1;
      }
  }else {
    echo "未查询到";
  }
  echo "</tr>";
?>

相关文章

网友评论

      本文标题:[笔记]php连接mysql数据库

      本文链接:https://www.haomeiwen.com/subject/kmzfsktx.html