Aureole Posted March 26, 2008 Share Posted March 26, 2008 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.' ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/ Share on other sites More sharing options...
teng84 Posted March 26, 2008 Share Posted March 26, 2008 seems like you are not connecting properly ! Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-500903 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 Wow. I only get the error when using the num_rows() function, if I don't use it then there are no errors. Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-500905 Share on other sites More sharing options...
darkfreaks Posted March 26, 2008 Share Posted March 26, 2008 you need to be using mysql_affected_rows() Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-500932 Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 you need to be using mysql_affected_rows() I've always used mysql_num_rows() to check to see if I want to do something next. Why is that the case here? Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-500998 Share on other sites More sharing options...
darkfreaks Posted March 26, 2008 Share Posted March 26, 2008 num_rows only applies for insert statements as affcted rows applies more towards selects read up on it. Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-501019 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 I've always used num_rows for this... oh well, I'll try affectected_rows. Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-501202 Share on other sites More sharing options...
trq Posted March 26, 2008 Share Posted March 26, 2008 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; } Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-501206 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/97902-cant-get-this-to-work/#findComment-501278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.