Is it possible to profile Zend_Table queries? - zend-framework

I'm looking for a way to profile queries which are performed internally by Zend_Table.
For example, after you finish Quickstart course, how to profile all the queries that are performed ?
I've tried to enable profiler from application.ini like this:
resources.db.profiler.class = "Zend_Db_Profiler_Firebug"
resources.db.profiler.enabled = true
And placed next rows in a Guestbook controller:
...
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$profiler = $db->getProfiler();
echo $profiler->getTotalElapsedSecs();
Which gives me 0
I've also tried to enable profiler in a Bootstrap file like this:
protected function _initProfiler() {
$this->bootstrap("db");
$profiler = new Zend_Db_Profiler_Firebug("All DB Queries");
$profiler->setEnabled(true);
Zend_Registry::get("db")->setProfiler($profiler);
}
Whick doesn't give me any result (I've installed and tested Firebug and FirePHP, using Zend_Log_Writer_Firebug())
I will appreciate any help. Thanks !

I've not tried the Firebug profiler. But I do use a html table to output profiler info at the bottom of each page that does a query.
enable profiler in application.ini
resources.db.params.profiler = true
render the profile results in the layout:
<?php
$this->addScriptPath(APPLICATION_PATH . '/views/scripts');
echo $this->render('profiler.phtml')
?>
profiler.phtml the view to render
<?php
// get the default db adapter
$adapter = Zend_Db_Table::getDefaultAdapter();
$profiler = $adapter->getProfiler();
if ($profiler->getEnabled() && $profiler->getTotalNumQueries() > 0) :
?>
<div style='text-align:center'>
<h2>Database Profiling Report</h2>
<p>Total queries executed: <?php echo $profiler->getTotalNumQueries() ?></p>
<p>Total elapsed time: <?php echo $profiler->getTotalElapsedSecs() ?></p>
</div>
<table class='spreadsheet' cellpadding='0' cellspacing='0' style='margin:10px auto'>
<thead>
<tr>
<th>#</th>
<th>Query</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<?php foreach ($profiler->getQueryProfiles() as $queryNumber => $query) : ?>
<tr>
<td>(<?php echo $queryNumber + 1 ?>)</td>
<td><?php echo $query->getQuery(); ?></td>
<td><?php echo $query->getElapsedSecs(); ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif ?>
I don't imagine that using the firebug profiler is much more difficult.

The problem was in the parameters instantiation. When I've entered
resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug"
resources.db.params.profiler.enabled = true
instead of previous configuration, everything went fine.
Note .params section of the parameter lines

Related

Clear the filled data of form in Phalcon Framework

I am new to phalcon and trying to learn this framework. I have created a simple form. Now, When I fill up the form, I am able to store the data in database. After submitting the form I want to be on the same page. Now the issue is, form is still have the filled data it is not clearing up. I have googled and found the clear() method to clear the form data but it seems that its not working. What to do?
Here is my code
//Controller
use Phalcon\Mvc\Controller;
class ProfileController extends Controller
{
public function indexAction()
{
// Add some local CSS resources
$this->assets->addCss("css/styles.css");
$this->assets->addCss("css/bootstrap.min.css");
// And some local JavaScript resources
$this->assets->addJs("js/jquery.js");
$this->assets->addJs("js/bootstrap.min.js");
}
public function createAction(){
//create object of model class
$profile = new Tbl_profile();
$profile->fname= $this->request->getPost('firstname');
$profile->lname= $this->request->getPost('lastname');
$profile->email= $this->request->getPost('email');
$success=$profile->save();
if($success) {
$this->flash->success("Profile created!");
//redirect to same page.
$this->dispatcher->forward(['action' => 'index']);
}else {
}
}
}
//views
<html>
<head>
<title>Title</title>
<?php $this->assets->outputCss(); ?>
</head>
<body>
<h4 class="ml-5 mt-2"> Create Profile</h4>
<?php echo $this->getContent(); ?>
<?php echo $this->tag->form("profile/create") ?>
<table class="table">
<tbody>
<tr scope="row">
<td>First Name</td>
<td><?php echo $this->tag->textField("firstname"); ?></td>
</tr>
<tr scope="row">
<td>Last Name</td>
<td><?php echo $this->tag->textField("lastname"); ?></td>
</tr>
<tr scope="row">
<td>Email</td>
<td><?php echo $this->tag->textField("email"); ?></td>
</tr>
<tr scope="row">
<td></td>
<td><?php echo $this->tag->submitButton("Create");?></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Once you save the data to database, redirect to the controller instead of forwarding the request because forwarding the request won't reload the page.
$this->request->redirect('profile/index');
Read this what's the difference between redirect and dispatch in phalcon? for more information
You must create form class to have ability using $form->clear() method.
See the doc https://docs.phalconphp.com/cs/3.4/forms

$this->input->post() and $_POST is NULL in codeigniter

I am getting a problem in codeigniter where i have a view file called view.php.
<?php echo form_open('');?>
<table class="table">
<thead>
<tr>
<th>Full Name</th>
<th>Username</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo form_input('fullname1',$row_data['fullname']);?> </td>
<td><?php echo form_input('username1',$row_data['username']);?></td>
<td><?php echo anchor("welcome/save/".$row_data['rid'],form_button('button',"Save"));?></td>
</tr>
</tbody
</table>
<?php echo form_close();?>
and here is my save method
public function save($rid){
$arr=array('fullname'=>$this->input->post('fullname1'),
'username'=>$this->input->post('username1')
);
var_dump($_POST);
var_dump($arr);
}
both array varable giving me NULL values while the textboxes have the values Please Help.... Thanks
you need to add the url to your form_open method. Try
echo form_open("your_url");
give the path of your save method instead of your_url.
Also check documentation here
The form_open method demands a target url.
In View
# Syntax <?php echo form_open('controllerName/MethodName');?>
<?php echo form_open('welcome/save');?>
// remove this
<td><?php echo anchor("welcome/save/".$row_data['rid'],form_button('button',"Save"));?></td>
// Add this
echo form_submit('mysubmit', 'Submit Post!');
In Controller
public function save(){
$fullname= $this->input->post('fullname1');
$username = $this->input->post('username1');
echo "MY name is ".$fullname." UserName Is : "$username;
}
Read Form Helper Codeigniter and form-validation-using-codeigniter example

$wpdb error cant fix

i create custom plugin and i have table wp_customers , i try to select all things in my table but wordpress just show me Fatal error: Uncaught Error: Call to a member function get_results() on null in C:\xampp\htdocs\wordpress\wordpress\wp-content\plugins\rflredirection\public\showResult.php:4 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wordpress\wordpress\wp-content\plugins\rflredirection\public\showResult.php on line 4
i see codex , i use some antoher codes for select but i just that massege , this is my codes to try
global $wpdb;
$results = $wpdb->get_results('SELECT * FROM $wpd->wp_customers DESC ');
and
$results = $wpdb->get_results('SELECT * FROM wp_customers');
and
$table_name = $wpdb->prefix . "wp_customers";
$results = $wpdb->get_results("SELECT code FROM ".$table_name");
and i try get version but nothing
$dbVersion = $wpdb->db_version();
if ($dbVersion) {
echo "Running MySQL " . $dbVersion;
} else {
echo "MySQL version unavailable.";
}
When you use The wpdb Class, there is no need to include wp_ in tables name.
should be just like this:
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->customers");
// ^ use without (wp_)
Edit #1:
you have an error on foreach loop:
you should write foreach($results as $rows) instead of your error : foreach($rows as $results)
and don't forget the semicolons when get values, echo $rows["id"]; and so on..
your code should like:
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->customers");
?>
<body>
<table>
<tr>
<th>‌ID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>
<?php foreach($results as $rows){
?>
<tr>
<td>
<?php echo $rows["id"]; ?>
</td>
<td>
<?php echo $rows["name"]; ?>
</td>
<td>
<?php echo $rows["family"]; ?>
</td>
<td>
<?php echo $rows["numbers"]; ?>
</td>
<td>
<?php echo $rows["tell"]; ?>
</td>
<?php }?>
</tr>
</table>
Edit #2:
Copy all this lines and paste on top of your page to include wordpress package:
<?php
/**
* WordPress User Page
*
* Handles authentication, registering, resetting passwords, forgot password,
* and other user handling.
*
* #package WordPress
*/
// Make sure that the WordPress bootstrap has run before continuing.
require( dirname(__FILE__) . '/wp-load.php' );
// Now your page codes goes here ...

Zend_Form_Element_File (no decorator found error)

I am creating a form with an upload element. I have created the file element with the code below
$image = new Zend_Form_Element_File('image');
$image->setAttrib('title','Listing Image:')
->addDecorator('File')
->addValidator('Size', false, 204800)
->addValidator('Extension', false, 'jpg,png,gif');
$this->addElement($image);
Which as far as I can tell works fine. It tries to add a file element to the page. I get an error which says " Warning: No file decorator found... unable to render file element in..."
As you can see I have set the decorator for the element to be the File decorator so I am unsure why I am getting this error?
It is worth noting I have removed all default decorators except for viewHelper and PrepareElements and I am using a view partial as the viewHelper to display the output. Just incase this is required I have also included that below.
<form method="<?php echo $this->element->getMethod(); ?>" action="<?php echo $this->element->getAction(); ?>">
<div class="boxmiddle-Holder">
<div class="boxmiddle-content">
<table border="0" cellspacing="2" cellpadding="3" class="dataTable">
<?php foreach($this->element->getElements() as $element): ?>
<!-- if not a button then display label -->
<tr>
<td><label for="<?php echo $element->getName(); ?>"><?php echo $element->getAttrib('title'); ?></label></td>
<td class="normal"><?php echo $element; ?></td>
<?php if($element->getMessages()) {
foreach($element->getMessages() as $message) { ?>
<td> <?php echo "<p class='elementError'>".$message."</p>"; ?></td>
<?php }
}
?>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
Any ideas?
I'd double check to make sure the File decorator isn't being cleared or reset later, that error indicates that your form's file element does not have a Zend_Form_Decorator_File decorator attached to it.
Look in Zend/Form/Element/File.php around line 859 for the function that throws this error. I suspect somehow the File decorator is being removed from the element. It could be that it has no decorators or is just lacking the File decorator.
Hope that helps.

zend paginator make other links and Action Calling concatinating with the URL

I am NEW to ZF .i used zend paginator in my first project .its working fine that is switching b/w pages with right result but the problem is that i have other links too in that view have a look to my view
<?php include "header.phtml"; ?>
<h1><?php echo $this->escape($this->title);?></h1>
<h2><?php echo $this->escape($this->description);?></h2>
Register
<table border="1" align="center">
<tr>
<th>User Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</tr>
<?php
foreach($this->paginator as $record){?>
<tr>
<td><?php echo $record->user_name;?></td>
<td><?php echo $record->first_name;?></td>
<td><?php echo $record->last_name;?></td>
<td>
Edit
|
Delete
</td>
</tr>
<?php } ?>
</table>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
<?php include "footer.phtml"; ?>
as i said the pagination renders and working fine but when i click on these links
<a id="edit_link" href="edit/id/<?php echo $record->id;?>">Edit</a>
or
<a id="delete_link" href="del/id/<?php echo $record->id;?>">Delete</a>
or
Register
it is not calling the required action instead it make my url like this
(initial link) http://localhost/zend_login/web_root/index.php/task/list
after clicking any of the above link its like this
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/8
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/23
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/register http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/del/id/12
note its not happening when the page renders first time but when i click on any pagination link its doing so initialy its going to the reguired action and displaying a view...any help HERE IS THE ACTION
public function listAction(){
$registry = Zend_Registry::getInstance();
$DB = $registry['DB'];
$sql = "SELECT * FROM task ORDER BY task_name ASC";
$result = $DB->fetchAll($sql);
$page=$this->_getParam('page',1);
$paginator = Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(3);
$paginator->setCurrentPageNumber($page);
$this->view->assign('title','Task List');
$this->view->assign('description','Below, are the Task:');
$this->view->paginator=$paginator;
}
Try:
// controller
$this->view->controllerName = $this->getRequest()->getControllerName();
// view script
Edit
|
Delete
or
Edit
|
Delete
Second example uses baseUrl() view helper that's using front controller's baseUrl setting. If you don't set baseUrl in your frontController it's trying to guess. As you're not using bootstrap functionality to set baseUrl you may do the following in index.php (not required):
$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl('/');
Third possibility using url() view helper:
<a href="<?php echo $this->url(array(
'controller' => $controllerName,
'action' => 'edit',
'id' => $record_->id
)); ?>">Edit</a>
|
<a href="<?php echo $this->url(array(
'controller' => $controllerName,
'action' => 'del',
'id' => $record_->id
));?>">Delete</a>
add this in your action
$request = $this->getRequest();
$this->view->assign('url', $request->getBaseURL());
and replace your links in view with this
Add a Task
Edit
Delete