php - How to change code below from mysql() to PDO -


i have been researching , found out should using pdo , not mysql() in php connect database. research , able change of mmysql() code in multiple pages pdo, want know if can convert code below pdo can see , able use answer provided in order me change code in other pages well.

below code:

<?php  session_start();   $username="xxx"; $password="xxx"; $database="xxx";  mysql_connect('localhost',$username,$password);  mysql_select_db($database) or die( "unable select database");  $i = 0; $c = count($_post['gridvalues']);  $insertquestion = array();  for($i = 0;  $i < $c; $i++ ){       $optionquery = "select optionid option_table (optiontype = '". mysql_real_escape_string($selected_option)."')";     $optionrs = mysql_query($optionquery);     $optionrecord = mysql_fetch_array($optionrs);     $optionid = $optionrecord['optionid'];       $insertquestion[] = "'". mysql_real_escape_string($_session['id'] ) .                      ($_session['initial_count'] > 1 ? $_session['sessioncount'] : '') ."' ,'".                      mysql_real_escape_string( $_post['numquestion'][$i] ) ."','".                       mysql_real_escape_string( $optionid ) ."'";  }    $questionsql = "insert question (sessionid, questionid, questioncontent, noofanswers, replyid, questionmarks, optionid)      values (" . implode('), (', $insertquestion) . ")";  mysql_query($questionsql);  mysql_close();   ?> 

also pdo version of below:

$num = mysql_num_rows($result = mysql_query($query));   while($row = mysql_fetch_array($result)){ } 


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -