convert from mysqli to pdo

Question

I'm a rookie in MYSQL PDO, and I'm trying to convert from SQLi to PDO.

I have solved most of the line but one of the line I'm still getting errors after I changed to PDO.

please see code....

 <?php session_start();  include_once("../cs/db.php");

 //echo 'lll'.$_SESSION['user']; if(isset($_SESSION['user_id'])){

 if(isset($_SESSION['cart_id'])){

 $cart_id_session =

 $_SESSION['cart_id']; 

 }else{

 $q_fetch_cart_id = $conn->query("select cart_id from cart where user_id = 

  '".$_SESSION['user_id']."'");

 $cart_id_set = $q_fetch_cart_id ->fetch(PDO::FETCH_ASSOC);

 $cart_id_session = $cart_id_set[0];

 $_SESSION['cart_id'] = $cart_id_session;}}

 ?>

As you can see on last three lines, I changed to (PDO::FETCH_ASSOC); and that line have solved but then next line where it said

$cart_id_session = $cart_id_set[0];

I'm getting errors said

Undefined offset: 0

Is this has to do with PDO! if so what is correct code is!

Many thanks for your help. AM


Show source
| pdo   | mysql   | database   2017-01-05 19:01 0 Answers

Answers to convert from mysqli to pdo ( 0 )

Leave a reply to - convert from mysqli to pdo

◀ Go back