+ Reply to Thread
Results 1 to 3 of 3

Thread: Problem with the "quote" PDO function

  1. #1
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Problem with the "quote" PDO function

    Hello.

    I try to use the quote function of PDO to escape a string issued from a form. The connection with the DB seems to be establish, but I've this message :
    Fatal error: Call to a member function quote() on a non-object in /home/user/public_html/functions.php on line 5


    that's the function I use :
    PHP Code:
    include ('DB_Connect.inc');
    include (
    'functions.php');
    $ut $_POST['utilisateur'];
    $pa safe($_POST['upass']); 
    the script after that isn't executed because of the error.

    That's the included DB_Connect.inc :
    PHP Code:
    <?php
    //on se connecte ā la database
    $db  DB_name;
    $dbh = new PDO("mysql:host=localhost;dbname=$db"'user''password');
    $dbh->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
    ?>
    and the functions.php :
    PHP Code:
    <?php
    // ce fichier est un include php
    function safe($v) {
    // return mysql_real_escape_string($var);
    $ret $dbh->quote($v);
    return 
    $ret;
    }
    ?>
    I don't understand why that doesn't work ! Fore, I used a mysql_real_escape_string with a mysql connection (out of PDO) but all the rest of my script's access to DB was written with PDO. I'd like to uniformize, using only one connection via my include file DB_Connect.inc !!!

    Am I on the wrong way ?

    Thank you for your help.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Problem with the "quote" PDO function

    You need to declare $dbh as global within function safe($v), or pass $dbh as a parameter.
    Last edited by misson; 11-11-2009 at 05:14 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Re: Problem with the "quote" PDO function

    Thanks, Misson, that was rather simple ! :nuts:

    I declare it as global... and it works !

+ Reply to Thread

Similar Threads

  1. Weird problem connecting to MySQL
    By tupakapoor in forum Free Hosting
    Replies: 13
    Last Post: 01-24-2008, 01:35 AM
  2. Which is the problem of my account? Part 2 xD
    By GodMew in forum Free Hosting
    Replies: 2
    Last Post: 01-17-2008, 09:57 AM
  3. Problem uploading image (GD library problem)
    By HyDr@ in forum Free Hosting
    Replies: 1
    Last Post: 12-01-2006, 04:27 PM
  4. Ad code problem!
    By Akkarin in forum Free Hosting
    Replies: 8
    Last Post: 08-29-2005, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers