dsjzmrz78089 2017-05-13 12:28
浏览 41
已采纳

Mysql到Mysqli数据库连接

I need to migrate my code from mysql to mysqli. I am new with coding so probably the mistake I am doing is really silly but please help me.

<?php
  $host="localhost"; // Host name
  $db_username="koko_login"; // Mysql username
  $db_password="YES"; // Mysql password
  $db_name="koko_database"; // Database name
  $tbl_name="members"; // Table name

  // Connect to server and select databse.
  // mysql_connect("$host", "$db_username", "$db_password")or die("cannot connect");
  // mysql_select_db("$db_name")or die("cannot select DB");

  $connection = mysqli_connect( 'host', 'username', 'password');
  $database = mysqli_select_db($link, 'database');


  if (isset($_SESSION['username'])){
      $username = $_SESSION['username'];
      $password = $_SESSION['username'];
  }

  function generate_event_link($tbl_name, $username, $key)
  {
    $sql="SELECT * FROM $tbl_name WHERE username='$username'";
    $result=mysqli_query( $link, $query);
    $count=mysqli_num_rows( $result);
    $arr = mysqli_fetch_array( $result, $type);
    if ($arr[$key] != 0){
    $href= "http://localhost/koko/event_page.php?id=" . $arr[$key]; ?>
    <li class="divider"></li>
    <li><a href=<? echo $href ?>"#">Your Event<img class="img responsive pull-right" src="icons/house.png" alt="User"></a></li>
    <?}}
?>
  • 写回答

3条回答 默认 最新

  • douyu7879 2017-05-14 10:03
    关注

    Agreed with RiggsFolly, but notice variable $type is not defined anywhere and can also be removed

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环