Solved

MySQL Query Errors

Posted on 2014-09-11
4
154 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

Creating and Managing Databases with phpMyAdmin in cPanel.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 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