Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to convert a MySQL query into PDO?
    primarykey
    data
    text
    <p>I need to convert this into PDO form for a class, but since I am new to all of this, can someone please help me out? My professor claims that every function can be converted, but I can't find anything online that can help me.</p> <pre><code>&lt;?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-&gt;getMessage(); } function createTable ($name, $query) { if (tableExists($name)) { echo "Table '$name' already exists&lt;br /&gt;"; } else { queryMysql("CREATE TABLE $name($query)"); echo "Table '$name' created&lt;br /&gt;"; } } 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 "&lt;img src='$user.jpg' border='1' align='left' /&gt;"; } $result = queryMysql("SELECT * FROM rnprofiles WHERE user='$user'"); if (mysql_num_rows($result)) { $row = mysql_fetch_row($result); echo stripslashes($row[1]) . "&lt;br clear=left /&gt;&lt;br /&gt;"; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload