当我尝试测试我的再生形式时,这个按摩出现了: “mysql扩展已弃用,将来将被删除:使用mysqli或PDO”
每次遇到新问题时我都会尝试更改我的代码,我对这些内容并不擅长 任何人都可以帮助我,告诉我我的代码需要更改的内容吗?!
连接代码
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_localhost = "localhost";
$database_localhost = "rsms database";
$username_localhost = "root";
$password_localhost = "";
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);
?>
这是我的源代码
<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO users (email, DateOfBirth) VALUES (%s, %s)",
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['DateOfBirth'], "date"));
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
$insertGoTo = "PageAfterLogin.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_localhost, $localhost);
$query_RegesterUsers = "SELECT * FROM users";
$RegesterUsers = mysql_query($query_RegesterUsers, $localhost) or die(mysql_error());
$row_RegesterUsers = mysql_fetch_assoc($RegesterUsers);
$totalRows_RegesterUsers = mysql_num_rows($RegesterUsers);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div class="containerDiv" id="containerDiv">
Regesteration Page
<form method="POST" action="<?php echo $editFormAction; ?>" name="form">
<table width="600" border="0">
<tbody>
<tr>
<td><label for="email">Email:</label>
<input type="email" name="email" id="email"></td>
<td><label for="date">Date:</label>
<input type="date" name="DateOfBirth" id="DateOfBirth"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit"></td>
</tr>
</tbody>
</table>
<input type="hidden" name="MM_insert" value="form">
</form>
</div>
</body>
</html>
<?php
mysql_free_result($RegesterUsers);
?>
答案 0 :(得分:-1)
目前在PHP中有三种连接MySQL数据库的方法。使用mysql_ *函数(已使用),mysqli_ *(首选)和PDO。
不再支持mysql_函数(并在PHP 7中删除),您不应再使用它们用于PHP脚本,并且应该使用MySQLi作为新的和改进的标准。
PDO是所有数据库安装的通用标准,例如MySQL,SQLite,MS SQL和PostgreSQL。
您所拥有的信息只是一个通知,您不需要使用PDO或MySQLI,但PHP会在您每次更改脚本时告诉您。