php 警告:mysqli_select_db() 需要 2 个参数,1 个在 C:\
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26595886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\
提问by DesignerMind
I'm doing a tutorial in which the author has not updated his content to reflect changes in the PHP documentation. Anyways, I need to know what is parameter is being asked of me to provide. I've checked that all things are in order, but I literally don't know what I'm supposed to provide. Here's what I have:
我正在做一个教程,其中作者没有更新他的内容以反映 PHP 文档中的更改。无论如何,我需要知道要求我提供什么参数。我已经检查过所有东西都井然有序,但我真的不知道我应该提供什么。这是我所拥有的:
Connects.php
连接.php
<?php
$connect_error = 'Sorry, we\'re experiencing connection issues.';
$con = mysqli_connect('localhost', 'root', 'PwdSQL5');
mysqli_select_db('phpcadet') or die($connect_error);
?>
And yet I get the error:
然而我得到了错误:
Edit: After figuring out to resovle the Connects.php issue, here's why I get when fixed it... more errors and here's my code. Remember I'm new to PHP and am following a poorly done tutorial.
编辑:在找出解决 Connects.php 问题后,这就是为什么我在修复它时得到的原因......更多错误,这是我的代码。请记住,我是 PHP 新手,并且正在学习一个做得不好的教程。
Warning:mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in C:\vhosts\phpcadet\core\functions\general.php on line 4
警告:mysqli_real_escape_string() 期望参数 1 为 mysqli,字符串在 C:\vhosts\phpcadet\core\functions\general.php 第 4 行中给出
General.php
通用.php
<?php
function sanitize($data)
{
return mysqli_real_escape_string($data, 'What goes here?');
}
?>
Then this: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\vhosts\phpcadet\core\functions\users.php on line 7
那么这个:警告:mysqli_query() 期望参数 1 是 mysqli,在第 7 行 C:\vhosts\phpcadet\core\functions\users.php 中给出的字符串
Users.php
用户.php
<?php
require 'core/database/connects.php';
function user_exists($username)
{
$username = sanitize($username);
$query = mysqli_query($_POST['username'], "SELECT * FROM users");
$row = mysqli_fetch_array($query);
if($row['username']==$username)
{
echo "Welcome, $username!";
return true;
}
else echo "Please enter a valid username and password";
return false;
}
function user_active($username)
{
$username = sanitize($username);
$query = mysqli_query($_POST['username'], "SELECT * FROM users");
$row = mysqli_fetch_array($query);
if($row['username']==$username && $row['active']==1)
{
echo "Welcome, $username!";
return true;
}
else echo "Your username and password could not be verified.";
return false;
}
?>
And finally this: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\vhosts\phpcadet\core\functions\users.php on line 8
最后这个:警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,在 C:\vhosts\phpcadet\core\functions\users.php 第 8 行中给出为空
See same code above
见上面相同的代码
Some of my code is a compilation of other answers to solve issues with the lesson, and were found on Stack. Due to inconsistecy of them, it makes it hard for me to pick up what is going on... Coming from a different language, I not that familiar here, and just need the help, so it all clicks. Then I'll have "understanding" of what the manual is saying. Thanks.
我的一些代码是其他答案的汇编,用于解决课程中的问题,并在 Stack 上找到。由于它们的不一致,我很难了解正在发生的事情......来自不同的语言,我在这里不太熟悉,只是需要帮助,所以全部点击。然后我将“理解”手册所说的内容。谢谢。
回答by Jay Blanchard
mysqli_select_db()
should have 2parameters, the connection link and the database name -
mysqli_select_db()
应该有2 个参数,连接链接和数据库名称 -
mysqli_select_db($con, 'phpcadet') or die(mysqli_error($con));
Using mysqli_error
in the die statement will tell you exactlywhat is wrong as opposed to a generic error message.
使用mysqli_error
在模具的语句会告诉你究竟什么是错的,而不是一个一般错误消息。