Skip to main content
Tweeted twitter.com/#!/StackDrupal/status/215890720039501824
added 263 characters in body
Source Link
chlong
  • 653
  • 4
  • 15
  • 29

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?

PS. The following is the completeEdit - Updated with new code:

define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = "localhost";
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);    

$result = db_query('SELECT nameOFFICE_ID FROM {usersOFFICE} WHERE uid');
$counter = 1')->fetchField();0;
dpmforeach($result as $record); {
  $counter = $counter + 1;
  print $record->office_id;
}
print $counter;

Nothing will be printed, but at the end of the loop, the number of loops performed is the same as the number of rows returned from a direct query on the DB itself.

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?

PS. The following is the complete code:

define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = "localhost";
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);    

$result = db_query('SELECT name FROM {users} WHERE uid = 1')->fetchField();
dpm($result);

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?

Edit - Updated with new code:

define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = "localhost";
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$result = db_query('SELECT OFFICE_ID FROM {OFFICE}');
$counter = 0;
foreach($result as $record) {
  $counter = $counter + 1;
  print $record->office_id;
}
print $counter;

Nothing will be printed, but at the end of the loop, the number of loops performed is the same as the number of rows returned from a direct query on the DB itself.

added 248 characters in body
Source Link
chlong
  • 653
  • 4
  • 15
  • 29

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?

PS. The following is the complete code:

define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = "localhost";
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);    

$result = db_query('SELECT name FROM {users} WHERE uid = 1')->fetchField();
dpm($result);

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?

PS. The following is the complete code:

define('DRUPAL_ROOT', getcwd());
$_SERVER['REMOTE_ADDR'] = "localhost";
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);    

$result = db_query('SELECT name FROM {users} WHERE uid = 1')->fetchField();
dpm($result);
Source Link
chlong
  • 653
  • 4
  • 15
  • 29

db_query not returning anything (or empty) - drupal 7

I am trying to perform a db_query but am unable to do so.

The query I am trying to perform is very simple, but to make things even simpler, the following query does not even work for me:

$result = db_query('SELECT name FROM users WHERE uid = 1');

and if I do:

echo (string)$result->name;

nothing is displayed.

Does anyone know what could be causing this?