我需要將其轉換爲一個類的PDO形式,但由於我是所有這些的新手,有人可以幫助我嗎?我的教授聲稱每個功能都可以轉換,但是我找不到任何可以幫助我的功能。我想將一個MySQL查詢轉換爲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 />";
}
}
?>
,謝謝你的這種感受。幫助我超越文檔! –