Viewed   83 times

I am learning to work with PHP and have a simple problem.

   ini_set('display_errors', 'On');
  $db = new PDO('sqlite:/usr/users2/mieic2009/ei09072/public_html/TP1/Delicious    /Database.db');
   $a = $_GET['linkRef'];
   $b = $_GET['tagToAdd'];

   $checkIdLink = $db->prepare('SELECT idLink FROM Links WHERE nome_L = :link_n;');
   $checkIdLink->bindParam(':link_n', $a, PDO::PARAM_STR);
   $linkID = $checkIdLink->fetch();

   $insertLink = $db->prepare('INSERT INTO Tags (nome_T, idLink) VALUES (:addTag, :link_id)');
   $insertLink->bindParam(':addTag', $b, PDO::PARAM_STR);
   $insertLink->bindParam(':link_id', $linkID, PDO::PARAM_INT);

    echo 'Tag added to the specified link!';

This code should add a Tag to an existing link in a database, however I am getting this error

Fatal error: Call to a member function bindParam() on a non-object in /usr/users2/mieic2009/ei09072/public_html/TP1/Delicious/addTag.php on line 9

I have checked over and over and can't seem to find what's wrong with this code, I googled for this error but unfortunately the answer I found weren't helpful enough. Any help would be appreciated, this is probably a simple rookie mistake.



I would check that the $db->prepare() function executed successfully. It will return false if it did not. So you could be trying to call bindParam() on a variable that equals false

Also you should put the PDO object declaration in try/catch to be sure it was successful as well, as in the first example on this page:

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
Wednesday, August 24, 2022

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (

  -r, --register-only
        do not remove files, only register the packages as not installed

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

Monday, December 12, 2022

The answer was due to hidden characters located in the lessons.db file.

The error shown had nothing to do with this and I would like to thank everyone who took the time to give their two pence.

Wednesday, November 23, 2022

Your $result_project_material is probably empty or your query is failing.

Try to do step by step and find where is the error, check if the result is empty before calling fetch_array().

$connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if ($connect->connect_errno) {
   printf("Connect failed: %sn", $connect->connect_error());

$result_project_material = $connect->query($sql_project_material);

if($total_project_material = $result_project_material->num_rows > 0) {
   while($result_array = $result_project_material->fetch_array()) {
       $rows_project_material[] = result_array;
   $rows_project_material = array();
   echo "Empty Result";
Thursday, August 25, 2022

Never used any of those, but they look interesting..

Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..

Friday, November 11, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :