我需要开始使用 mysqli 扩展,但我发现各种冲突的信息取决于我尝试使用的所有信息的方式。
例如,我的标头连接到当前如下所示的“config.php”文件:
<?php
$hostname_em = "localhost";
$database_em = "test";
$username_em = "user";
$password_em = "pass";
$em = mysql_pconnect($hostname_em, $username_em, $password_em) or trigger_error(mysql_error(),E_USER_ERROR);
?>
但是当我去 php.net 时,我发现我应该使用它,但是在更新了所有内容之后,我没有得到任何数据库。
<?php
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
我还经历了并在我的网站的以下代码中添加了一个“i”,但还是没有运气:
mysql_select_db($database_em, $em);
$query_getReview =
"SELECT
reviews.title,
reviews.cover_art,
reviews.blog_entry,
reviews.rating,
reviews.published,
reviews.updated,
artists.artists_name,
contributors.contributors_name,
contributors.contributors_photo,
contributors.contributors_popup,
categories_name
FROM
reviews
JOIN artists ON artists.id = reviews.artistid
JOIN contributors ON contributors.id = reviews.contributorid
JOIN categories ON categories.id = reviews.categoryid
ORDER BY reviews.updated DESC LIMIT 3";
$getReview = mysql_query($query_getReview, $em) or die(mysql_error());
$row_getReview = mysql_fetch_assoc($getReview);
$totalRows_getReview = mysql_num_rows($getReview);
到目前为止,这是我的显示页面上唯一提到 mysql 的地方:
<?php } while ($row_getReview = mysql_fetch_assoc($getReview)); ?>
我确实在 oracle 看到了另一个 stackoverflow 答案指向某人自动更新这些东西的东西,但此时我的代码太少了,看起来有点矫枉过正。