Solved

MySQL Query Errors

Posted on 2014-09-11
4
153 Views
Last Modified: 2014-09-29
I'm testing a simple SQL query from my Products table, in the Navigator_Data database, whihc is the second database to my Drupal site.

I put this in a Block (PHP code text format), and get this error.

<?php
  $navigator_array = array(
      'database' => 'navigator_data',
      'username' => 'sandshakimi', 
      'password' => 'XXX', 
      'host' => 'localhost', 
      'driver' => 'mysql', 
  );
  Database::addConnectionInfo('PRODUCT', 'default', $navigator_data);
  db_set_active('PRODUCT');
  $result = mysql_query('SELECT * FROM `PRODUCT` ');
  db_set_active(); // without the paramater means set back to the default for the site

?>

Open in new window


 SCscdata-2.JPG
0
Comment
Question by:sandshakimi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40317787
Those functions must come from Drupal because they are not PHP functions.  Except... mysql_query() is probably Not the method being used in Drupal.  They are probably using the 'mysqli' driver which is different than the 'mysql' driver.  Look at the Drupal code to find their method of doing a query.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40317958
I have not verified this, but at first glance it looks like it's on target.
http://alvinalexander.com/mysql/drupal-create-mysql-database-user-account-example
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40320052
I think db_query() may be the Drupal wrapper for PHP mysql_query().  The problem appears to be caused by missing or incorrect authentication credentials, or missing permissions in the MySQL database.
0
 
LVL 13

Accepted Solution

by:
Arrow_1 earned 500 total points
ID: 40320090
You should be defining your database connection info in your settings.php file. It should look something like this:
$databases['nav_data']['default'] = array(
    'database' => 'navigator_data',
    'username' => 'sandshakimi',
    'password' => 'XXX',
    'host' => 'localhost',
    'driver' => 'mysql',
);

Open in new window


Then in your code, access it this way:
$nav_data = Database::getConnection('default', 'nav_data');
$result = $nav_data->query('SELECT * FROM `PRODUCT` ');

Open in new window


or this way:
db_set_active('nav_data');
$result = db_query('SELECT * FROM `PRODUCT` ');
db_set_active();

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question