1

I'm looking to see if it's possible to execute a raw SQL statement from a PHP controller action. Currently, I'm trying to execute a block of code that I build within the controller action to insert values into a table within my database...

$sql = "BEGIN INSERT INTO HOSTS VALUES('1', 'hostname1'); INSERT INTO HOSTS VALUES('2', 'hostname2'); END;";
$db->exec($sql);

Is something similar to the above code possible to be handled within a controller/action, or do I need to pursue a different route? Thank you in advance.

1 Answer 1

1

I figured out you can reference your DB credentials within the application.ini file and execute the SQL statement using said credentials. This can be done within the controller page of your code.

$sql = "BEGIN INSERT INTO HOSTS VALUES('1', 'hostname1'); INSERT INTO HOSTS VALUES('2', 'hostname2'); END;";
$stmt = Zend_Registry::get('DBNAME')->prepare($sql);
$stmt->execute();
Sign up to request clarification or add additional context in comments.

Comments

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.