Custom grid event using mysqli

QuestionsCustom grid event using mysqli
Cliff asked 11 years ago

I am having trouble getting a custom update event to work with my grid. I'm using mysqli and the mysqli_query command requires a $connection as the first parameter, followed by the sql to execute as the second parameter. For example:

$result1=mysqli_query($connection,"UPDATE tbluser SET UserFirstName='xxx' WHERE idtblAdminUser = y");

What should I use as the $connection parameter? I am connecting to the database using:
$db_conf = array();
$db_conf["type"] = "mysqli";
$db_conf["server"] = $hostname_TW; // or you mysql ip
$db_conf["user"] = $username_TW; // username
$db_conf["password"] = $password_TW; // password
$db_conf["database"] = $database_TW; // database

// include and create object
include("/phpGrid/lib/inc/jqgrid_dist.php");

$g = new jqgrid($db_conf);

Can you provide a working example of a custom update grid event using mysqli please?
Thanks,
Cliff

6 Answers
Abu Ghufran answered 11 years ago

Hello,

You can make g rid object as global var inside function.

$grid = new jqgrid();

And inside your callback handler:

global $grid;
$grid->execute_query("YOUR-SQL");

This will use existing connection to run query. You can also check 'execute_query' function code inside jqgrid_dist.php

Cliff answered 11 years ago

Wow, that's a very fast response – thank you! I'll give it a try and let you know if I'm still struggling.
Thanks,
Cliff

Abu Ghufran answered 11 years ago

You can use,

global $grid;
$result = $grid->execute_query($sql);
$arr = $result->GetRows();

Basically, it return adodb recordset object. api can be checked from adodb docs:
http://phplens.com/lens/adodb/docs-adodb.htm

Montemaggiore Sebastian answered 9 years ago

Hello. I have a similar problem. What happen when the slq sentences returns values?.

Ananda Theerthan answered 8 years ago

When I try to use execute_query(), i get below error,
'Call to a member function execute_query() on a non-object'
$g6 = new jqgrid();

function check_total_2($data6)
{
global $g6;

$check_sql = "CALL sp_getStudentDataAjax('{$data6["params"]["student_user_id"]}','{$data6["params"]["testid"]}')";
$rs = $g6->execute_query($check_sql);
$r = $rs->GetRows($rs);
}

Abu Ghufran answered 8 years ago

This error explains that $g6 is not object of new jqgrid() when you call the function.
You can try re-creating $g6 = new jqgrid(); inside function again and remove the global var.

Your Answer

10 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?