Call to undefined method PDO::fetchColumn()
<p>I'm trying to generate a random number and insert it among other information if it doesn't exist in the same column. All with AJAX, so it is in another php file.<br>
I'm using this:</p>

<pre><code>$dbhost = "127.0.0.1";
$dbuser = "root";
$dbpass = "";
$dbname = "feely";
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);

function func(){
   $success = false;
   while (!$success) {
      $rndInt = rand(0, pow(36, 6) - 1);
      $rndStr = base_convert ($rndInt, 10, 36);
      $rndStr = str_pad($rndStr , 6, "0", STR_PAD_LEFT);
      global $db;

      $query = "SELECT * FROM pedidos WHERE Codigo = {$rndStr} LIMIT 1";
      $db-&gt;query($query);
      if (!$db-&gt;fetchColumn()) { // value does not exist yet
         // insert new random value
         //$db-&gt;query($query);
         $success = true; // will terminate the loop
         return $rndStr;
      } else { // value already exists
         // do nothing - try again in the next loop
      }
   }
}

$code = func();
$device= $_POST['devicename'];
$issue= $_POST['issue'];

$sql = "insert into pedidos (Code, Device, Issue) values (";
$sql .= "'$codigo', '$device', '$issue')";

if(mysqli_query($db, $sql)){
   echo 'success';
}
</code></pre>

<p>But I'm getting:-</p>

<blockquote>
  <p>"Call to undefined method PDO::fetchColumn()".</p>
</blockquote>

<p>It is important to say that I'm a front-end developer, so... :D  </p>

<p>Help ;-;</p>