Jump to content

Can't get this to work...


Aureole

Recommended Posts

I'm having a little database trouble.

 

The select function is working fine...

 

<?php
    function select( $select, $table, $where = '' )
    {
    	$this->query = "SELECT {$select} FROM `{$table}`";

    	if( $where !== '' )
    	{
    		$this->query .= " WHERE";

		if( is_array( $where ) )
		{
    		foreach( $where as $f => $v )
    		{
    			$nval = ( is_numeric( $v ) && intval( $v ) == $v ) ? $v : "'{$v}'";

				$this->query .= " `$f` = $nval AND";
			}
		}
		else
		{
			$nwhere = explode( '|', $where );

			$nval = ( is_numeric( $nwhere[1] ) && intval( $nwhere[1] ) == $nwhere[1] ) ? $nwhere[1] : "'{$nwhere[1]}'";

			$this->query .= " `$nwhere[0]` = $nval";
		}
    	}

	$this->query = substr( $this->query, 0, -4 );

	return( $this->query );
    }
?>

 

...as is this...

 

<?php
function exec_query()
{
	return $this->result = mysql_query( $this->query );
}
?>

 

...but this isn't...

 

<?php
    function num_rows()
    {
	return mysql_num_rows( $this->result );
    }
?>

 

When I try to use it, I get:

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\sources\classes\class_database.php on line 308

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\sources\classes\class_database.php on line 308

 

Otherwise there are no errors.

 

The actual code, is:

 

<?php
$lname = md5( $_POST['mem_lname'] );
$pass = md5( $_POST['mem_pass'] );

$db->select( '*', 'members', array( 'mem_lname' => $lname, 'mem_pass' => $pass ) );
$db->exec_query();

if( $db->num_rows > 0 )
{
echo( 'Login success.' );
}
else
{
echo( 'Login failure.' );
}
?>

Link to comment
Share on other sites

num_rows only applies for insert statements as affcted rows applies more towards selects read up on it.

 

That is exactly the oposite to the truth.

 

either way, you have a connection issue. Can wee see where you make your connection? Also, this function....

 

function exec_query()
{
	return $this->result = mysql_query( $this->query );
}

 

should be....

 

function exec_query()
{
	$this->result = mysql_query( $this->query );
                          return $this->result;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.