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
https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/
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
https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-501206
Share on other sites

I changed the function as you stated and I have fixed the connection problem, silly error on my part... I created a new topic with my new problem, been as though this topic was basically to do with the connection problem.

 

Here's a link to the topic

 

It explains everything a lot better.

 

Consider this topic solved.

Link to comment
https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-501278
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.