WordPress.org

Ready to get started?Download WordPress

Forums

Insert PHP
[resolved] Resource id #250 (6 posts)

  1. blakemoore123
    Member
    Posted 1 year ago #

    I'm trying to connect to a database and display the contents of the wp_users table.

    The connection is working... but when i try to echo the results of the sql query i just get Resource id #250 in it's place.

    http://wordpress.org/extend/plugins/insert-php/

  2. WillBontrager
    Member
    Plugin Author

    Posted 1 year ago #

    Post the code you have between the [insert_php] and [/insert_php] tags. I'll see what I can see.

  3. WillBontrager
    Member
    Plugin Author

    Posted 1 year ago #

    I'm assuming the OP resolved the issue as there was no response.

  4. blakemoore123
    Member
    Posted 1 year ago #

    This is not resolved.

    [insert_php]
    $con = mysql_connect("MY SERVER","MY USERNAME","MY PASS");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("MY DATABASE");
    
    $results = mysql_query("select * from wp_users") or die(mysql_error());
    
    if($results)
    {
    echo "$results";
    }
    else
    {
    echo "Failed";
    }
    [/insert_php]

    Cheers Will!

  5. WillBontrager
    Member
    Plugin Author

    Posted 1 year ago #

    Use mysqli_connect and its associated mysqli_... functions instead of mysql_connect.

    Two reasons.

    1. mysql_connect is being deprecated.
    (See http://us3.php.net/manual/en/function.mysql-connect.php )

    2. I've found that accessing MySQL with my own code concurrently with WordPress using MySQL can fail when I use mysql_connect.

    Will

  6. WillBontrager
    Member
    Plugin Author

    Posted 1 year ago #

    One more thing. This is not a forum on how to write PHP code, and I'm not going to let it become one. However, here is one more tip:

    If you want to see the results of your SELECT query, you'll need to fetch the data from $result with a function for that purpose, mysqli_fetch_assoc() for example.

    Will

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic