WordPress.org

Ready to get started?Download WordPress

Forums

Connecting to database inside wordpress? (2 posts)

  1. winrid
    Member
    Posted 2 years ago #

    Hello!
    I'm attempting to read from a database inside wordpress itself, and even though the code works, I get the error

    "Warning: mysql_error(): 14 is not a valid MySQL-Link resource in /home/content/06/5950706/html/zootesting/wp-includes/wp-db.php on line 1081"

    Anybody know any solutions?

    The code:

    <?php
    $conz = mysql_connect("xxxxxxxx", "xxxxxxxxxx", "xxxx") or die(mysql_error());
    mysql_select_db("wpzoogala", $conz);
    $queryv="SELECT * FROM locations";
    $resultv=mysql_query($queryv,$conz) or die(mysql_error());
    $zing = 1;
    while($rowq = mysql_fetch_array($resultv))
      {
    		if($zing == 1) {
    		$curvarz = $rowq['countrycode'];
    		echo "<option value='0' selected='selected'>".$curvarz."</option>";
    		}
    		else {
    		$curvarz = $rowq['countrycode'];
    			if($curvarz != $oldline) {
    			echo "<option value='0' selected='selected'>".$curvarz."</option>";
    			}
    		}
    
    		$oldline = $rowq['countrycode'];
    	$zing = 0;
      }
       mysql_close($conz);
      ?>
  2. shazdeh
    Member
    Posted 2 years ago #

    Why aren't you using the $wpdb global object? Also checkout Codex on databases, WP has built-in function for working with databases.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.