Results 1 to 7 of 7

Thread: include mysql connections

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default include mysql connections

    I can include absolute filenames and relative filenames, but when I include the following file:
    PHP Code:
     <?php
    $conn 
    mysql_connect("mysql""username""password") or die(mysql_error());
     
    mysql_select_db("db",$conn)  or die(mysql_error());
    ?>
    using
    PHP Code:
    <?php include 
    'http://www.mysite.com/dbstuff.php';
    $topic "select stuff from admin where ID=0";
    $verify mysql_query($topic$conn) or die(mysql_error());?>
    I get the error:
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/m/y/s/mysite/html/test.php on line 4.

    If I use
    PHP Code:
    <?php
    include 'dbstuff.php';
    ?>
    everything works great.

    Is this a security feature? I am just surprised that using absolute filenames for other files works just fine. Hmm, maybe I will look into this further. No worries about responding right away to this post. I might be able to figure some more of this puzzle out soon.
    Last edited by james438; 10-10-2008 at 04:21 PM.

  2. #2
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    If allow_url_fopen is enabled, you can include a file using a URL. If not, only filesystem paths will be accepted.

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    it is enabled and I can include files by URL, but not when dealing with sql connections like in my example above. thanks for looking into it though.

  4. #4
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    Are you trying to open a connection to a database on a remote server?

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I use godaddy, so I do not really know.

    here is my php5.ini file. As far as I can tell there is nothing private in this file so
    Code:
    register_globals = off
    
    allow_url_fopen = on
    
    allow_url_include = on
    expose_php = Off
    
    max_input_time = 60
    
    variables_order = "EGPCS"
    
    extension_dir = ./
    upload_tmp_dir = /tmp
    precision = 12
    SMTP = relay-hosting.secureserver.net
    url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="
    
    [Zend]
    zend_extension=/usr/local/zo/ZendExtensionManager.so
    zend_extension=/usr/local/zo/4_3/ZendOptimizer.so
    From what I can tell including database connections will work only if the applications of the database connections are located in the included file as well. Otherwise the database connections will need to be included relatively.

    The error I get when including database connections absolutely look like
    Code:
    Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/m/y/s/mysite/html/review/addform.php on line 22
    
    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/content/m/y/s/mysite/html/review/addform.php on line 22
    Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)
    Last edited by james438; 10-10-2008 at 07:39 AM.

  6. #6
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    Quote Originally Posted by james438 View Post
    I use godaddy, so I do not really know.
    Well, you should know if you are trying to access a MySQL server on your site or on a remote site.

    But, that error is the result of trying to include the file using a url. The http wrapper is preventing the mysql connection as this could be a request from a remote site, and thus a security risk.

    It should work if you include() the file using a file system path.

  7. The Following User Says Thank You to BabblingIdjit For This Useful Post:

    james438 (10-11-2008)

  8. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Ah, so it is being prevented due to security issues. That is good. Thanks for the info.

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
  •