gpt4 book ai didi

php - mySQL Object of class mysqli_result could not be converted to string问题

转载 作者:行者123 更新时间:2023-11-30 22:16:01 62 4
gpt4 key购买 nike

<分区>

我在尝试获取 mySQL 中特定字符串的 id 时遇到问题

我的 table :

ID |         URL       |
1 | http://google.com |

当我放这个V

    SELECT ID FROM urls
WHERE url LIKE ('http://google.com')

将代码写入 mySQL 它确实显示 ID 1,但我试图让它显示在我网站的页面上。

下面的代码是我试图显示此代码的页面的代码。

<?php
// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// sql to create table
$url = 'http://google.com';
$ip = $_SERVER['REMOTE_ADDR'];

$sql = "
SELECT ID FROM urls
WHERE url LIKE ('http://google.com')
";

$result = $conn->query($sql);

echo $result;
$conn->close();

是的,我已经定义了 DB_HOST、DB_USER、DB_PASS 和 DB_NAME,它们工作正常。

每当我执行代码时,都会出现此错误消息。

Catchable fatal error: Object of class mysqli_result could not be converted to string in /home/u926065153/public_html/db_t.php on line 16

请注意,我没有很多 SQL 经验,这是我的学习方式。

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com