我需要将其转换为课程的 PDO 形式,但由于我对这一切都不熟悉,有人可以帮我吗?我的教授声称每个功能都可以转换,但我在网上找不到任何可以帮助我的东西。
<?php
// rnfunctions.php
$dbhost = 'localhost';
$dbname = 'social_local';
$dbuser = 'root';
$dbpass = 'root';
$appname = "Social Networking Test Site";
try
{
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch ( PDOException $e )
{
echo $e->getMessage();
}
function createTable ($name, $query)
{
if (tableExists($name)) {
echo "Table '$name' already exists<br />";
} else {
queryMysql("CREATE TABLE $name($query)");
echo "Table '$name' created<br />";
}
}
function tableExists ($name)
{
$result = queryMysql("SHOW TABLES LIKE '$name'");
return mysql_num_rows($result);
}
function queryMysql ($query)
{
$result = mysql_query($query) or die(mysql_error());
return $result;
}
function destroySession ()
{
$_SESSION = array();
if (session_id() != "" || isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time() - 2592000, '/');
}
session_destroy();
}
function sanitizeString ($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
$var = stripslashes($var);
return $var;
}
function showProfile ($user)
{
if (file_exists("$user.jpg")) {
echo "<img src='$user.jpg' border='1' align='left' />";
}
$result = queryMysql("SELECT * FROM rnprofiles WHERE user='$user'");
if (mysql_num_rows($result)) {
$row = mysql_fetch_row($result);
echo stripslashes($row[1]) . "<br clear=left /><br />";
}
}
?>