gpt4 book ai didi

php - 警告 : mysqli_connect() expects parameter 5 to be long, 中给出的字符串

转载 作者:行者123 更新时间:2023-11-30 22:55:27 25 4
gpt4 key购买 nike

我知道已经有人问过这个问题,但似乎对我的问题没有任何帮助。我需要从数据库中获取一些数据并将其显示在 HTML 中。

代码是这样的:

<?php

$host="localhost"; // Host name
$username="bluecode_power"; // Mysql username
$password="bluecode123"; // Mysql password
$db_name="bluecode_login"; // Database name
$tbl_name="news"; // Table name

$myConnection= mysqli_connect("$host", "$date", "$user", "$title", "$text")or die("cannot connect");
mysqli_select_db("$db_name")or die("cannot select database");

$query = "SELECT * FROM news"; //You don't need a ; like you do in SQL
$result = mysql_query($query);

echo "<table>"; // start a table tag in the HTML

while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['date'] . "</td><td>" . $row['news'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML

mysql_close();

?>

感谢任何想法:)

最佳答案

你在哪里定义$text变量? $text 的值是一个字符串,尽管 mysqli_connect() 中的第五个参数是端口 # 并期望传递一个长值或整数值。

$myConnection= mysqli_connect("$host", "$date", "$user", "$title", "$text")or die("无法连接");

应该是:

$myConnection = mysql_connect( $host, $username, $password, $db_name ) or die("无法连接");

关于php - 警告 : mysqli_connect() expects parameter 5 to be long, 中给出的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26597087/

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