警告:mysqli_query()要求参数2为字符串,对象在C:\ wamp \ www中给出

时间:2015-07-28 09:51:30

标签: php

当我尝试这段代码时,我收到有关字符串的第二个参数的警告。我在以前的类似问题中看到了一些答案,但我没有找到解决方案...据我所知,问题在于if语句?谢谢。

if (isset($_GET['id'])) {

    $str_id = $_GET['id'];

    ($conn->set_charset("utf8"));   

    if ($result=mysqli_query($conn, $q )) {
        while ($obj=mysqli_fetch_object($result)) {
        }
?>

1 个答案:

答案 0 :(得分:0)

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";

if ($result=mysqli_query($con,$sql))
  {
  while ($obj=mysqli_fetch_object($result))
    {
    printf("%s (%s)\n",$obj->Lastname,$obj->Age);
    }
  // Free result set
  mysqli_free_result($result);
}

mysqli_close($con);
?>