SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict o~~Goatee~~o's Avatar
    Join Date
    Jan 2004
    Location
    North Yorkshire UK
    Posts
    350
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_real_escape_string() problem

    Hi there

    I developed an application which worked perfectly fine locally with the following setup:

    Apache version : Apache/1.3.33 (Win32)
    PHP version : 5.0.4
    MySQL version : 4.1.10a-nt - extension : mysqli

    The application has now been setup on a different server with the same configuration as above but we get the following error where the mysql_real_escape_string() function is used:

    Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in c:\wamp\www\PACKSPEC\pallet_admin.php on line 37

    Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in c:\wamp\www\PACKSPEC\pallet_admin.php on line 37
    If I remove the function and just leave the raw value it all works fine.

    Any ideas as to how I can fix this? I'm wondering if I have to establish a connection before using this function?

    Many thanks

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried using the link_identifier parameter?
    mysql_real_escape_string ( string unescaped_string [, resource link_identifier] )

    The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.
    Sounds like your problem to me

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by o~~Goatee~~o
    I'm wondering if I have to establish a connection before using this function?
    Yes.

  4. #4
    SitePoint Addict o~~Goatee~~o's Avatar
    Join Date
    Jan 2004
    Location
    North Yorkshire UK
    Posts
    350
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for the replies. I've currently fixed the problem by calling my mySQLConnect() funtion before using the mysql_real_escape_string() function. However, after using mysql_real_escape_string() I use my mySQLQuery() function which itself calls the my mySQLConnect function. Is it a problem connecting to MySQL twice like this?

    Thanks

  5. #5
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Connecting twice is not catastrophic, but pretty inaccurate. If you're not using any oop wrapper (which solves the problem automatically), you can work around by creating procedural wrapper for mysql_connect and a static variable:

    PHP Code:
    function my_connect() {
       static 
    $conn null;
       if(
    is_null($conn))
          
    $conn mysql_connect(<your connection data>)
       return 
    $conn;

    This function will connect only once, no matter how many times it's called.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •