Forums

[ask] how to ACCESS data from OTHER DATABASE ? (5 posts)

  1. c_a_k_r_a
    Member
    Posted 3 years ago #

    How to get data from other database ?

    Since other database have a different information (host,username,password) with the default one define at wp-config.php so using $wpdb command always failed.

    I create native php-mysql database connect in one file (grabdata.php) and include it in widget (php-enable-widget using plugin) and this code screw other $wpdb command after this code.

    grabdata.php :

    <?
    $con = mysql_connect('localhost','username','pass')
                                or die(mysql_error());
    mysql_select_db('mydatabase')     or die(mysql_error());
    
    $sql = 'SELECT <code>inbox</code>.<code>ReceivingDateTime</code>, <code>inbox</code>.<code>SenderNumber</code>, <code>inbox</code>.<code>TextDecoded</code>'
            . ' FROM inbox'
            . ' WHERE (<code>inbox</code>.<code>RecipientID</code> =\'0811111111111\')'
            . ' ORDER BY <code>inbox</code>.<code>ReceivingDateTime</code> DESC'
    		. ' LIMIT 0 , 10';
    $result = mysql_query($sql) or die(mysql_error());
    echo "<ul>";
    while ($line = mysql_fetch_array($result)){
      	echo "<li><small>From : </small><strong>".$line[1]."</strong> <small>@ ".$line[0]."</small><span style=\"color:#CCC\">".$line[2]."</span></li>";
    };
    echo "</ul>";
    mysql_close($con);
    ?>

    Note : this grabdata.php give the true result and run smooth if run independently.

    The error message in almost every place that acces wp database after that code is :
    Warning: mysql_error(): 10 is not a valid MySQL-Link resource in ...my-path../wp-includes/wp-db.php on line 615

    wp-db on line 615 is :

    // If there is an error then take note of it..
    		if ( $this->last_error = mysql_error($this->dbh) ) {
    			$this->print_error();
    			return false;
    		}

    Any help will be appreciated..
    Thanks..
    Cakra

    [moderated--bump removed. Please refrain from bumping as per Forum Rules]

  2. cuban_cigar
    Member
    Posted 3 years ago #

    it would be cool if someone could crack the database accessing problem..

  3. MichaelH
    Volunteer
    Posted 3 years ago #

  4. cordoval
    Member
    Posted 2 years ago #

    I was able to solve my problem modifying the function on my database manipulation to include the mysql_select_db function and commenting the mysql_close function safely.

  5. flaminglogos
    Member
    Posted 2 years ago #

    I've access data from a separate database using the $wpdb class that is included in the WP code. It takes the hassle out of manually setting up the database connections.

    I've posted the details on my original thread.

Topic Closed

This topic has been closed to new replies.

About this Topic