0

I have just updated my server from php 5.3 to php 5.6 and now for some reason a web page I have no longer works. It throws this error:

Fatal error: Call to undefined method PDOStatement::bind_param()

and I can't figure out what I have got wrong. I'd really appreciate any help.

The php (not all of it)

include("connect.php"); //include config file
session_start(); // start up your PHP session! 

//sanitize post value
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);

//throw HTTP error if page number is not valid
if(!is_numeric($page_number)){
    header('HTTP/1.1 500 Invalid page number!');
    exit();
}

//get current starting point of records
$position = (($page_number-1) * $item_per_page);

//fetch records using page position and item per page. 
$results = $conn->prepare("SELECT up.id, up.file, up.title, p.user_name, p.user_id, GROUP_CONCAT(CONCAT(cp.user_id, '~', cp.user_name) SEPARATOR '|') AS tagGroup
FROM tbl_uploads up
LEFT JOIN tbl_users p ON up.user_id = p.user_id
LEFT JOIN tbl_collab c ON up.file = c.file AND c.approved = 'yes'
LEFT JOIN tbl_users cp ON cp.user_id = c.collab_userid
GROUP BY up.file ORDER BY up.id DESC LIMIT ?, ?");

//Where approved stops new images being displayed 

        //bind parameters for markers
        $results->bind_param("dd", $position, $item_per_page);
        $results->execute(); //Execute prepared Query
        $results->bind_result($id,$file,$title,$user_name,$user_id,$tagGroup); //bind variables to prepared statement

$i=0;

        while($results->fetch()){ //fetch values

connect.php

$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
JulianJ
  • 1,259
  • 3
  • 22
  • 52
  • 1
    Good question. You should get it with both, because it's `bindParam` for PDO. `bind_param` is mysqli. – aynber Feb 03 '17 at 17:59
  • Thanks. I changed to bindParam and now get this error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'. Any ideas? – JulianJ Feb 03 '17 at 18:06
  • where is `$item_per_page` set? – cmorrissey Feb 03 '17 at 18:10
  • 1
    You never put `dd` in your query (which should be `:dd` anyway). You're using `?` for placeholders instead of using named placeholders. Pick one type of placeholder and stick with it. Actually, it's another case of mysqli vs PDO. Read up on [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) to find the best way to do it. – aynber Feb 03 '17 at 18:12

0 Answers0