Results 1 to 4 of 4

Thread: Problem connecting to mysql

  1. #1
    Join Date
    Dec 2008
    Posts
    29

    Problem connecting to mysql

    I'm currently working on a script for uploading images as a blob in Mysql.

    The script is working but when I connect my own class to go incl uden than does the script halfjes. I can only upload pictures but do not display correctly.
    The reason that I connect a class that I have is always changing so I can not all files need to run.

    Original connect part of the script:

    php:
    <?
    <? php
    $db_host = 'localhost' ; // don't forget to change
    $db_user = 'mysql-user' ;
    $db_pwd = 'mysql-password' ;

    $database = 'test' ;
    $table = 'ae_gallery' ;
    // use the same name as SQL table


    if (! mysql_connect ( $db_host , $db_user , $db_pwd ))
    die( "Can't connect to database" );

    if (! mysql_select_db ( $database ))
    die( "Can't select database" );
    ?>

    The way I have adapted:

    php:
    <?
    //Include Mysql class
    include( '../classes/mysql_connect.class.php' );

    //Connect to Mysql via class
    $connection = new connect_db ();
    $connection -> connect ();

    $db_host = $connection -> host ; // don't forget to change
    $db_user = $connection -> user ;
    $db_pwd = $connection -> pwd ;

    $database = $connection -> db ;
    $table = 'imagegallery' ;
    // use the same name as SQL table

    $password = '123' ;
    // simple upload restriction,
    // to disallow uploading to everyone


    if (! mysql_connect ( $db_host , $db_user , $db_pwd ))
    die( "Can't connect to database" );

    if (! mysql_select_db ( $database ))
    die( "Can't select database" );
    ?>
    This works ... but not quite.

    My connect.class:

    php:

    <?php

    class connect_db
    {
    var $host = "localhost" ;
    var $user = "user" ;
    var $pwd = "pass" ;
    var $db = "database" ;

    function connect ()
    {
    $connection = mysql_connect ( $this -> host , $this -> user , $this -> pwd ) or die ( "Error: " . mysql_error (). " Nr.: " . mysql_errno ());

    if( $connection )
    {
    $select_db = mysql_select_db ( $this -> db ) or die ( "Error: " . mysql_error (). " Nr.: " . mysql_errno ());
    }
    }

    }

    ?>

    I think this is a very strange problem because normally works.

    Anyone can help?
    thank you

  2. #2
    Join Date
    Dec 2008
    Posts
    196

    Re: Problem connecting to mysql

    Do you vars in your class in a __CONSTRUCT__ stabbing, because that method was, I thought on some servers do not work correctly.

    edit: something discovered:
    You make the connection class ($ connect_db-> connect ()), and then in the non-class too ...
    1x is enough?

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Problem connecting to mysql

    In non-class as I remove the connection than he says he can not connect: S
    Hence a variable that I have put down there that links to the var in connect.class

  4. #4
    Join Date
    Dec 2008
    Posts
    322

    Re: Problem connecting to mysql

    i am not much good in this but i think ..Maybe output is sent before the image is.

Similar Threads

  1. Connecting C# with MySQL database
    By Quattro in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 10:13 PM
  2. Connecting to remote MySQL
    By Gavisht in forum Software Development
    Replies: 4
    Last Post: 10-12-2009, 08:35 PM
  3. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  4. Problem connecting to mysql db
    By Wagan-rave in forum Software Development
    Replies: 3
    Last Post: 21-03-2009, 10:57 AM
  5. Connecting VB.net with mysql
    By Jateen in forum Software Development
    Replies: 1
    Last Post: 05-01-2009, 09:37 PM

Tags for this Thread

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
  •  
Page generated in 1,714,111,436.15093 seconds with 16 queries