2

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);

2 Answers 2

2

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

//Delete database
 $sql = "DROP DATABASE `". $dbName."`";
Sign up to request clarification or add additional context in comments.

9 Comments

I've tried. It throws error as "Syntax error or access violation"
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
What is your database name?
It's a fake Db i made. "aaa-test-fake-co_fc". The db name won't matter I guess.
I updated my answer please try it. If it will work then I explain why this?
|
0

$sql = 'DROP DATABASE'. $dbName;

I think you missed a space

$sql = 'DROP DATABASE '. $dbName;

6 Comments

I've tried. It throws error as "Syntax error or access violation"
@user3386487 it seems your mysql user doesn't have privilege to drop the database
Ive just deleted db from console from same username. It seems like its a Zend issue. Can you help me on that?
@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.
@hd1-Yes, i can from xampp-shell.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.