Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I cannot delete database from raw MySql query here. Is there a better way? Please suggest. Is there a way to write a query to drop database in Zend. I'm using Zend 1.11

// Delete db function
public function deleteDB($dbName){
// For database connection
$config = new Zend_Config( 
    array(
    'database' => array(
    'adapter' => 'PDO_MYSQL',
    'params'  => array(
    'host'     => 'localhost',
    'dbname'   => $dbName,
    'username' => 'root',
    'password' => '',
            )
    )
    )
);
 $db = Zend_Db::factory($config->database);

 //Delete database
 $sql = 'DROP DATABASE'. $dbName;
 $db->query($sql);
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

If your configuration is correct then try to put space after DATABASE like

//Delete database
 $sql = "DROP DATABASE `". $dbName."`";
share|improve this answer
    
I've tried. It throws error as "Syntax error or access violation" –  Shirshak Jun 25 at 6:07
    
Can you give your full error message –  Sadikhasan Jun 25 at 6:08
    
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 –  Shirshak Jun 25 at 6:17
    
What is your database name? –  Sadikhasan Jun 25 at 6:19
    
It's a fake Db i made. "aaa-test-fake-co_fc". The db name won't matter I guess. –  Shirshak Jun 25 at 6:22
show 5 more comments

$sql = 'DROP DATABASE'. $dbName;

I think you missed a space

$sql = 'DROP DATABASE '. $dbName;

share|improve this answer
    
I've tried. It throws error as "Syntax error or access violation" –  Shirshak Jun 25 at 6:07
    
@user3386487 it seems your mysql user doesn't have privilege to drop the database –  leo108 Jun 25 at 6:10
    
Ive just deleted db from console from same username. It seems like its a Zend issue. Can you help me on that? –  Shirshak Jun 25 at 6:20
    
@hd1 can't you? –  leo108 Jun 25 at 6:31
    
@user3386487 another possibility is that the mysql user you used in php and in console is different, although they use the same name, It depends on what db hostname you connected. –  leo108 Jun 25 at 6:35
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.