我不知道我做错了什么,但收到了这个错误: -
不推荐使用:mysql_connect():不推荐使用mysql扩展 将来将被删除:使用mysqli或PDO代替 第7行的C:\ wamp \ www \ includes \ config.php
我该如何解决这个问题?
<?php
$mysql_hostname = "localhost";
$mysql_user = "bootstrapadmin";
$mysql_password = "";
$mysql_database = "bootstrap";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Mate you fucked something up!");
mysql_select_db($mysql_database, $bd) or die("Mate you fucked something up!");
?>
现在我遇到登录页面的问题
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\login.php on line 12
Call Stack
# Time Memory Function Location
1 0.0012 140512 {main}( ) ..\login.php:0
2 0.0079 149352 mysqli_query ( ) ..\login.php:12
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\wamp\www\login.php on line 13
Call Stack
# Time Memory Function Location
1 0.0012 140512 {main}( ) ..\login.php:0
2 0.0960 149752 mysql_num_rows ( ) ..\login.php:13
<?php
session_start();
include("includes/config.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//username and password sent from form
$myusername = addslashes($_POST['username']);
$mypassword = md5(addslashes($_POST['password']));
$sql = "SELECT userid FROM tbl_users WHERE username='$myusername' and password='$mypassword'";
$result = mysqli_query($sql);
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if ($count == 1) {
//$session_register("myusername");
$_SESSION['login_admin'] = $myusername;
header("location: http://localhost/admin/");
}
}
?>
答案 0 :(得分:0)
mysql_*
个函数。您可以使用mysqli_*
功能。例如:
<?php
$mysql_hostname = "localhost";
$mysql_user = "bootstrapadmin";
$mysql_password = "";
$mysql_database = "bootstrap";
$bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Mate you messed something up!");
mysqli_select_db($mysql_database, $bd) or die("Mate you messed something up!");
?>
答案 1 :(得分:0)
您是否搜索过MySQLi或PDO?
旧的mysql_*
方法已弃用,将在即将发布的PHP版本中删除。
在我看来,PDO是最好的方法,但只需转换为MySQLi即可。只需研究一下,然后使用其中一种新技术。
对于MySQLi,基本上只需将最后两行更改为:
$connection = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Mate you fucked something up!");
mysqli_select_db($connection, $mysql_database) or die("Mate you fucked something up!");
(添加&#34; i&#34;&#34; mysql&#34; /也在db-selection上切换参数)
有关MySQLi的更多信息:http://www.w3schools.com/php/php_ref_mysqli.asp