mysql vs mysqli配置文件和查询 [英] mysql vs mysqli config file and queries

查看:116
本文介绍了mysql vs mysqli配置文件和查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开始使用mysqli扩展名,但是我发现各种冲突的信息取决于我要使用的所有信息。

I need start using the mysqli extension but I'm finding all kinds of conflicting info depending on how all the info is that I'm trying to use.

例如,我的标头连接到当前如下所示的 config.php文件:

For example, my header connects to a 'config.php' file that currently looks like this:

<?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时,我看到我应该使用它,但是在更新所有内容后

But when I go to php.net I see that I should be using this but after updating everything I get no database.

<?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,再次没有运气:

I also went through and added an "i" to the following code in my site and again no luck:

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的地方:

And here's the only place on my display page that even mentions mysql so far:

<?php } while ($row_getReview = mysql_fetch_assoc($getReview)); ?>

我确实在oracle上看到了另一个stackoverflow答案指出某人自动地更新了这些东西的东西,但是我

I did see something at oracle that another stackoverflow answer pointed someone to that updates this stuff automagically, but I have so little code at this point it seems like overkill.

推荐答案

在任何mysql函数中添加i不会使它成为a有效的mysqli函数。即使存在这样的功能,也可能参数不同。在这里看看 http://php.net/manual/zh/book.mysqli.php 并花一些时间检查mysqli函数。也许尝试一些例子来熟悉事物的工作方式。我也建议您选择任何一种面向对象的代码或过程。不要混在一起。

Adding an i to any mysql function won't make it a valid mysqli function. Even if such function exists, maybe the parameteres are different. Take a look here http://php.net/manual/en/book.mysqli.php and take some time to check mysqli functions. Maybe try some examples to become familiar with the way things work. I also reccomend you to choose either object oriented code, either procedural. Don't mix them.

这篇关于mysql vs mysqli配置文件和查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆