lalaila Posted July 21, 2012 Share Posted July 21, 2012 Hi, Need help fixing Mysql error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gint/public_html/skelbimai/classes/mysql.php on [color=red]line 235[/color] Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gint/public_html/skelbimai/classes/mysql.php on [color=red]line 235[/color] Warning: Cannot modify header information - headers already sent by (output started at /home/gint/public_html/skelbimai/classes/mysql.php:235) in /home/gint/public_html/skelbimai/admin/addgroup.php on [color=red]line 30[/color] <?php class db_mysql { public function db_mysql( ) { global $config_db_server; global $config_db_server_username; global $config_db_server_password; global $config_db_database; $password = str_replace( "\$", "\$", $config_db_server_password ); $this->link = @mysql_connect( $config_db_server, $config_db_server_username, $password ); $this->errorQuery = array( ); $this->error = ""; $this->limit = ""; $this->offset = ""; $this->errorPath = ""; if ( $this->link ) { if ( @mysql_select_db( $config_db_database, $this->link ) ) { $this->recent_link =& $this->link; global $config_db_charset; global $config_db_collation; global $mysql_locale; global $mysql_names; if ( $mysql_locale != "" ) { mysql_query( "SET lc_time_names = '".$mysql_locale."'" ); } if ( $mysql_names != "" ) { mysql_query( "SET NAMES {$mysql_names}" ); } return $this->link; } $this->errorPath = $this->getErrorPath( ); $this->error = "Could not select database: {$config_db_database}"; } else { $this->error = "Could not connect to server: {$config_db_server}"; $this->errorPath = $this->getErrorPath( ); } } public function test( ) { return 1; } public function geterror( ) { global $config_debug; $str = "<span>Database query error. </span>"; if ( $config_debug ) { $str .= "<span>The error was: </span>".$this->error; $str .= "<br><span>SQL query/queries : </span>".$this->printErrorQuery( )."<span>Error path:</span> ".$this->errorPath; } return $str; } public function printerrorquery( ) { $result = ""; foreach ( $this->errorQuery as $str ) { $result .= $str."<br>"; } return $result; } public function setsql( $sql ) { $this->sql = $sql; } public function getsql( ) { return $this->sql; } public function query( $sql = "" ) { if ( $sql ) { $this->sql = $sql; } if ( !is_resource( $this->link ) ) { return false; } $this->recent_link =& $this->link; if ( 0 < $this->limit || 0 < $this->offset ) { $this->sql .= " LIMIT ".$this->offset.", ".$this->limit; } $result = @mysql_query( $this->sql, $this->link ); ++$this->query_count; if ( !$result ) { $this->error( ); $this->errorPath = $this->getErrorPath( ); return false; } return $result; } public function fetchrow( $sql = "" ) { if ( $sql ) { $this->sql = $sql; } if ( !( $result = $this->query( ) ) ) { return null; } $ret = null; if ( $row = @mysql_fetch_row( $result ) ) { $ret = $row[0]; } $this->freeResult( $result ); return $ret; } public function fetchrowres( $result ) { $ret = null; if ( $row = @mysql_fetch_row( $result ) ) { $ret = $row[0]; } return $ret; } public function fetchassocres( $result ) { $ret = null; if ( $row = @mysql_fetch_assoc( $result ) ) { $ret = $row; } return $ret; } public function fetchrowlist( $sql = "" ) { if ( $sql ) { $this->sql = $sql; } if ( !( $result = $this->query( ) ) ) { return null; } $array = array( ); while ( $row = @mysql_fetch_row( $result ) ) { $array[] = $row[0]; } $this->freeResult( $result ); return $array; } public function fetchassoc( $sql = "" ) { if ( $sql ) { $this->sql = $sql; } if ( !( $result = $this->query( ) ) ) { return null; } $ret = null; if ( $row = @mysql_fetch_assoc( $result ) ) { $ret = $row; } $this->freeResult( $result ); return $ret; } public function fetchassoclist( $sql = "" ) { if ( $sql ) { $this->sql = $sql; } if ( !( $result = $this->query( ) ) ) { return null; } $array = array( ); while ( $row = @mysql_fetch_assoc( $result ) ) { $array[] = $row; } $this->freeResult( $result ); return $array; } public function fetcharray( $sql = "" ) { if ( $sql ) { $this->sql = $sql; } if ( !( $result = $this->query( ) ) ) { return null; } $array = array( ); while ( $row = @mysql_fetch_array( $result ) ) { $array[] = $row; } $this->freeResult( $result ); return $array; } public function numrows( $result ) { [color=red][b]line 235[/b][/color] return mysql_num_rows( $result ); } public function affectedrows( ) { return mysql_affected_rows( $this->recent_link ); } public function numqueries( ) { return $this->query_count; } public function insertid( ) { return mysql_insert_id( $this->link ); } public function freeresult( $result ) { return mysql_free_result( $result ); } public function setoffset( $off ) { $this->offset = $off; } public function setlimit( $lim ) { $this->limit = $lim; } public function close( ) { $this->sql = ""; return mysql_close( $this->link ); } public function error( $err = "" ) { if ( $err ) { $this->error .= $err; } else { if ( is_null( $this->recent_link ) ) { return; } $this->error = " errno : ".mysql_errno( $this->recent_link )." ".mysql_error( $this->recent_link ); } $no = count( $this->errorQuery ); $this->errorQuery[$no] = $this->sql; return $this->error; } public function geterrorpath( ) { if ( $_SERVER['REQUEST_URI'] ) { $errorpath = $_SERVER['REQUEST_URI']; } else { if ( $_SERVER['PATH_INFO'] ) { $errorpath = $_SERVER['PATH_INFO']; } else { $errorpath = $_SERVER['PHP_SELF']; } if ( $_SERVER['QUERY_STRING'] ) { $errorpath .= "?".$_SERVER['QUERY_STRING']; } } if ( ( $pos = strpos( $errorpath, "?" ) ) !== false ) { $errorpath = urldecode( substr( $errorpath, 0, $pos ) ).substr( $errorpath, $pos ); } else { $errorpath = urldecode( $errorpath ); } return $_SERVER['HTTP_HOST'].$errorpath; } public function gettablefields( $table ) { $array = array( ); $res = mysql_query( "DESCRIBE ".$table ); $i = 0; while ( $row = mysql_fetch_row( $res ) ) { $array[$i] = $row[0]; ++$i; } return $array; } public function getfulltablefields( $table ) { $array = array( ); $res = mysql_query( "DESCRIBE ".$table ); $i = 0; while ( $row = mysql_fetch_assoc( $res ) ) { $array[$i]['Field'] = $row['Field']; $array[$i]['Type'] = $row['Type']; ++$i; } return $array; } public function gettablecsvfields( $table ) { $fields = ""; $res = mysql_query( "DESCRIBE ".$table ); $i = 0; while ( $row = mysql_fetch_row( $res ) ) { if ( $i ) { $fields .= ","; } $fields .= $row[0]; ++$i; } return $fields; } public function gettexttablefields( $table ) { $array = array( ); $res = mysql_query( "DESCRIBE ".$table ); $i = 0; while ( $row = mysql_fetch_row( $res ) ) { if ( !strstr( $row[1], "varchar" ) && $row[1] != "text" ) { continue; } $array[$i] = $row[0]; ++$i; } return $array; } public function gettables( $prefix = "", $not_prefix = "" ) { if ( !( $result = $this->fetchRowList( "SHOW TABLES" ) ) ) { return 0; } if ( !$prefix ) { return $result; } $i = 0; $arr = array( ); foreach ( $result as $row ) { if ( preg_match( "/^{$prefix}/", $row ) && !preg_match( "/^{$not_prefix}/", $row ) ) { $arr[$i++] = $row; } } return $arr; } } ?> Thanks all for help! Link to comment https://forums.phpfreaks.com/topic/266031-need-help-fixing-mysql-php-error/ Share on other sites More sharing options...
Barand Posted July 21, 2012 Share Posted July 21, 2012 Error messages indicates your query failed. Check why with mysql_error() Link to comment https://forums.phpfreaks.com/topic/266031-need-help-fixing-mysql-php-error/#findComment-1363240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.