PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The following code works fine in my dev station running PHP 5, but I just uploaded it to a server with PHP 4 and it broke. I believe it has something to do with the object in use:
Warning: array_values() [function.array-values]: The argument should be an array in /home/tutlib/public_html/vtl_content/plugins/to-do-list/to-do-list.php on line 31
Warning: array_values() [function.array-values]: The argument should be an array in /home/tutlib/public_html/vtl_content/plugins/to-do-list/to-do-list.php on line 32
Warning: Invalid argument supplied for foreach() in /home/tutlib/public_html/vtl_content/plugins/to-do-list/to-do-list.php on line 33
The function that resides in was something I got from the PHP manual from one of the comments that discussed issues with array_combine in PHP 4. The poster of that function mentioned that it fixed that and when I tried it on the server, it seemed to work as the array_combine issue was the first problem I ran into prior to what I'm running into now. Should I use something else?
Have you checked and confirmed that '$vtldb->get_results($query);' actually does return a result array? Does the database on the server support sub queries?
redmonkey wrote:Have you checked and confirmed that '$vtldb->get_results($query);' actually does return a result array? Does the database on the server support sub queries?
It's funny you mention this because after applying the workaround, I noticed that I'm having problems getting things to and from the database. Is this going to require a consult with the systems admin or is there yet again another workaround for this too?
SELECT id, user_login FROM $vtldb->users INNER JOIN $vtldb->usermeta ON $vtldb->users.id = $vtldb->usermeta.user_id WHERE $vtldb->usermeta.meta_value = 'administrator' ORDER BY id ASC LIMIT 10000
And I'm still not getting anything from the MySQL database. Have I done something wrong here?
mysql_error() doesn't appear to be throwing any errors and when I use the MySQL Console to type out that query (to test it), it comes back saying that it's returned an empty set. This leads me to believe that this new query is not picking up the tables / columns that I am trying to get it to retrieve (unless there's some sort of compatibility issue at hand).
AlanG: Here is the function definition of get_results() -
function query($query) {
if ( ! $this->ready )
return false;
// filter the query, if filters are available
// NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
if ( function_exists('apply_filters') )
$query = apply_filters('query', $query);
// initialise return
$return_val = 0;
$this->flush();
// Log how the function was called
$this->func_call = "\$db->query(\"$query\")";
// Keep track of the last query for debug..
$this->last_query = $query;
// Perform the query via std mysql_query function..
if ( defined('SAVEQUERIES') && SAVEQUERIES )
$this->timer_start();
$this->result = @mysql_query($query, $this->dbh);
++$this->num_queries;
if ( defined('SAVEQUERIES') && SAVEQUERIES )
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
// If there is an error then take note of it..
if ( $this->last_error = mysql_error($this->dbh) ) {
$this->print_error();
return false;
}
if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {
$this->rows_affected = mysql_affected_rows($this->dbh);
// Take note of the insert_id
if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
$this->insert_id = mysql_insert_id($this->dbh);
}
// Return number of rows affected
$return_val = $this->rows_affected;
} else {
$i = 0;
while ($i < @mysql_num_fields($this->result)) {
$this->col_info[$i] = @mysql_fetch_field($this->result);
$i++;
}
$num_rows = 0;
while ( $row = @mysql_fetch_object($this->result) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
@mysql_free_result($this->result);
// Log number of rows the query returned
$this->num_rows = $num_rows;
// Return number of rows selected
$return_val = $this->num_rows;
}
return $return_val;
}