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
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
Share on other sites

Check your $res variable, probably your query(*) has an error.

 

*

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

 

Debug your query with simple constants example in phpMyAdmin.

 

Link to comment
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
Share on other sites

Yeah, subtitue your dynamic variables with constants.

 

E.g change "TBL_LANG_KEY" to "lang_key"... and check in PHP your values, whether good/wrong. E.g your $_where_definition variable is a correct mysql where statement and etc...

Link to comment
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
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
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
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.