Get KoolPHP UI with 30% OFF!

How to connect KoolGrid to a MySQL DataSource using MySQLI

Stephen Harmon
All of the KoolGrid Examples show how to connect to a MySQL Datasource using the OLD METHOD. However, if you are using the current stable MySQL and PHP (which I'm running under MAMP currently), the OLD METHOD (as follows) has been deprecated.
Here is the old method I speak of:
// Create Datasource
$conn = mysql_connect($host, $username, $password);
mysql_select_db($default_dbname, $db_conn);
$ds = new MySQLDataSource($db_conn);
However, the new method would be something like this. But with my lack of experience I can't seem to get this to work. I get the following PHP error but can't understand everything as the KoolGrid.php is obfuscated.
$conn = new mysqli($host, $username, $password, $db);
$ds = $conn;
Warning: mysql_set_charset() expects parameter 2 to be resource, object given in /KoolControls/KoolGrid/koolgrid.php on line 1
Warning: mysql_query() expects parameter 2 to be resource, object given in /KoolControls/KoolGrid/koolgrid.php on line 1
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in /KoolControls/KoolGrid/koolgrid.php on line 1
Posted Nov 3, 2015 Kool
Anthony Amolochitis
You can do the following to connect via MySqli
$Db = new mysqli( $DB_Credential->host , $DB_Credential->username , $DB_Credential->password ,"",$DB_Credential->port ) ;
..
.. some code here to build your grid as usual
..
// set the data source
$KoolGrid->DataSource = new MySQLiDataSource($Db );

The rest is the same.
Posted Nov 4, 2015 Kool
Stephen Harmon
OK, something is not quite right. Dumb this down a little for me...
Here is what I have:
<?php 
    $KoolControlsFolder = "KoolControls";
    require "KoolControls/KoolGrid/koolgrid.php";
    require "KoolControls/KoolAjax/koolajax.php";
    $koolajax->scriptFolder = "KoolControls/KoolAjax";
    
    // Database & Connection
	$host = "localhost";
	$username = "testUsername";
	$password = "testPassword";
	$db = "testDB";
	
	$conn = new mysqli($host, $username, $password, $db);
    $ds = new MySQLiDataSource($conn);
    
    $ds->SelectCommand = "select * from drivers";
    $grid = new KoolGrid("grid");
    $grid->scriptFolder = "KoolControls/KoolGrid";
    $grid->DataSource = $ds;

And I still get the following error:
[04-Nov-2015 15:19:22 America/Denver] PHP Fatal error: Class 'MySQLiDataSource' not found in /workspace/manage.php on line 9
Posted Nov 4, 2015 Kool -
Anthony Amolochitis
require the datasource
/KoolControls/KoolGrid/ext/datasources/MySQLiDataSource.php
Posted Nov 5, 2015 Kool -
Peter
Thanks Anthony for your answer :)
Posted Nov 5, 2015 Kool -