Jump to content

fetch_assoc() error


Daimler

Recommended Posts

I installed a script and when i go to administration > languages i receive the fallowing error:

 

Fatal error: Call to a member function fetch_assoc() on a non-object in /home/site/public_html/admin/inc/fnc.lang_search.php on line 83

 

on line 83 i have this:  while ($row = $res->fetch_assoc())

 

Any ideeas please ?:)

Link to comment
https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/
Share on other sites

This is the all code:

<?php

 

function searchLangKeys($phrase, $search_key, $search_value) {

 

$_search = array( '%', '_', '*' );

$_replace = array( '\\%', '\\_', '%' );

 

$_phrase = str_replace( $_search, $_replace, ' '.mysql_real_escape_string( trim( $phrase ) ).' ' );

 

$_phrase = str_replace( ' ', '%', $_phrase );

 

$_where_definition = array();

if( $search_key )

$_where[] = '`key` LIKE ?phrase';

if( $search_value )

$_where[] = '`value` LIKE ?phrase';

 

$_where_definition = empty( $_where ) ? '1' : implode( ' OR ', $_where );

 

$def_lang = SK_Config::section('languages')->get('default_lang_id');

 

$query = sql_placeholder( "SELECT `section` , `parent_section_id`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value`

FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`)

LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`) WHERE (".$_where_definition.")",

array( 'phrase' => $_phrase )  );

 

$keys = array();

 

$res = SK_MySQL::query($query);

 

while ($row = $res->fetch_assoc()) {

$path = '';

if ($row['parent_section_id'] != 0) {

$path = $row['section'];

$parent_sect = $row['parent_section_id'];

do {

$query = sql_placeholder( "SELECT `parent_section_id`, `section`, `lang_section_id`,

`".TBL_LANG_KEY."`.`lang_key_id`, `key`

FROM `".TBL_LANG_SECTION."`

LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`)

WHERE `lang_section_id` = ?", $parent_sect );

 

$parent = SK_MySQL::query($query)->fetch_assoc();

$parent_sect = $parent['parent_section_id'];

 

$end = strlen($path) == 0 ? "" : "." . $path;

$path = $parent['section'] . $end;

}

while ( $parent_sect != 0);

 

$row['path'] = $path;

}

else $row['path'] = $row['section'];

 

$keys[] = $row;

}

 

return $keys;

}

 

 

function getMissingLabels($lang_id)

{

$languages_num = count(SK_LanguageEdit::getLanguages());

 

$missing_labels = MySQL::FetchArray( "SELECT `lang_key_id`

FROM `".TBL_LANG_KEY."`

WHERE `lang_key_id` NOT IN

(SELECT `lang_key_id` from `".TBL_LANG_VALUE."` WHERE `lang_id`=".$lang_id." AND `value` != '')");

 

if (is_array($missing_labels)) {

 

foreach( $missing_labels as $id => $num )

{

$query = "SELECT `section` , `parent_section_id`, `lang_section_id`,

`".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value`

FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`)

LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`)

WHERE `lang_key_id`=".$num['lang_key_id']." GROUP BY `lang_key_id`";

 

$res = SK_MySQL::query($query);

 

while ($row = $res->fetch_assoc())

{

$path = '';

if ($row['parent_section_id'] != 0) {

$path = $row['section'];

$parent_sect = $row['parent_section_id'];

do {

$query = "SELECT `parent_section_id`, `section`, `lang_section_id`,

`".TBL_LANG_KEY."`.`lang_key_id`, `key`

FROM `".TBL_LANG_SECTION."`

LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`)

WHERE `lang_section_id` =" . $parent_sect ;

 

$parent = SK_MySQL::query($query)->fetch_assoc();

$parent_sect = $parent['parent_section_id'];

 

$end = strlen($path) == 0 ? "" : "." . $path;

$path = $parent['section'] . $end;

}

while ( $parent_sect != 0);

 

$row['path'] = $path;

}

else $row['path'] = $row['section'];

 

$keys['labels'][] = $row;

}

}

$keys['total'] = count($keys['labels']);

}

else {

$keys = array();

$keys['total'] = 0;

}

 

return $keys;

}

 

Link to comment
https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089590
Share on other sites

One of your query probably wrong:

 

$query = sql_placeholder( "SELECT `section` , `parent_section_id`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value`

      FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`)

      LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`) WHERE (".$_where_definition.")",

      array( 'phrase' => $_phrase )  );

 

$query = "SELECT `section` , `parent_section_id`, `lang_section_id`,

            `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value`

            FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`)

            LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`)

            WHERE `lang_key_id`=".$num['lang_key_id']." GROUP BY `lang_key_id`";

 

Try to test it with simple constants. If its good with sample values, than your dynamic php values wrong.

 

Link to comment
https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089596
Share on other sites

Hey, i changed that TBL_LANG_KEY and others TBL * with lang_key and etc. and i receive this errors now:

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=1 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=8 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=13 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=14 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=15 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=16 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist

in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=19 AND `value` != '')

in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50

 

Link to comment
https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089605
Share on other sites

Hmm i dont think this problem is in script: i installed thos script on my localhost (xampp) and all works fine but not on my webserver.  :-[ what could this be ?

Did you also move the database? Because you can't host the php files somewhere else if you don't change the address from localhost to your ip and open some ports

Link to comment
https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089613
Share on other sites

bh

 

sure i dont understood you i am a beginner.  thanks for being so pactient with me, but were can i see the correct constants? in the phpmyadmin tables ? or ?

Your configuration is wrong. Localhost is your own computer.

You installed your site on a webserver, somewhere else. If you tell php to go look for a database on localhost, it will look on the pc that php is installed on, your webserver.

 

You have to put your database on the same pc as the webserver or edit the host to match your own pc (believe me, this can be very hard en frustrating the first few times, do the first thing)

Link to comment
https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1090011
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.