Loading Data from DB with php connector

Hello,

i have some troubles to load data in my grid from DB with php connector.

I follow this tutorial [url]Start DHTMLX Docs*

But i have no idea why it doesn’t work like in the example.

index.html

[code]

Tableau avec Grid
	<link rel="STYLESHEET" type="text/css" href="dhtmlConnector/codebase/dhtmlx.css">
<script  src="../codebase/dhtmlx.js"></script>	
<script type="text/javascript" src="dhtmlxConnector/codebase/connector/connector.js"></script>

<link rel="STYLESHEET" type="text/css" href="dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxgrid.css">
 <script src="dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
 <script src="dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>
 <script src="dhtmlxGrid/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
 <script src="dhtmlxGrid/dhtmlxGrid/codebase/ext/dhtmlxgrid_export.js"></script>
 <script>
 var mygrid;
 function doInitGrid(){
		// creates a grid instance
		mygrid = new dhtmlXGridObject('mygrid_container');
		// sets the path to the grid images
		mygrid.setImagePath("dhtmlxGrid/dhtmlxGrid/codebase/imgs/");
		// sets the headers of the columns
		//var mygrid = new dhtmlXGridObject('box');// object constructor
		mygrid.setHeader("ARTNUM,Test, Test2");//specifies the grid's headers
	
		
		// sets the width of the columns; * - the column fills all the available space
		// Regarder la personnalisation de skin
		// Essayer de mettre le maximum de ligne dans une fonction pour éviter la répétition lors de création de tableaux
		mygrid.setInitWidths("*,150,150");
		// sets the horizontal alignment of the value in the columns 
		mygrid.setColAlign("left,right,right");
		//mygrid.setColAlign(0,"left");
		// sets the skin of the grid
		mygrid.setSkin("light");
		
		
		// sets the sorting criteria of the columns
		mygrid.setColSorting("");
		// sets the types of the columns
		mygrid.setColTypes("ro"); 			
		
		// populates the grid with the data in XML format
		mygrid.init();//initializes the grid
		mygrid.load("php/data.php");//populates the grid with data from the DB
		 
		//---dataProcessor initialization
		var mydp = new dataProcessor ("php/data.php");// object constructor. Here you should specify a connector file
		mydp.init(mygrid);// initializes dataProcessor. As the parameter you should specify your grid
		 
					
		// adds a new row to the grid
		function addRow(){
			var newId = (new Date()).valueOf()
			mygrid.addRow(newId,"",mygrid.getRowsNum())
			mygrid.selectRow(mygrid.getRowIndex(newId),false,false,true);
    	}
		// remove the selected row from the grid
		function removeRow(){
			var selId = mygrid.getSelectedId()
			mygrid.deleteRow(selId);
		}
	}
 </script>
Add Row Remove Row [/code]

data.php :

[code]<?php
require_once(“dhtmlxConnector/codebase/connector/grid_connector.php”);// includes the appropriate connector

$res=mysql_connect(“myhost”,“mylogin”,“mypassword”);//connects to a server that contains the desired DB
mysql_select_db(“i5_articles”);// connects to the DB. ‘tasks’ is the name of our DB
$conn = new GridConnector($res,“MySQL”);// connector initialization
if(!$res)
{
die(‘Connexion impossible:’ .mysql_error());
}
echo ‘Connecte correctement’;
$conn->render_table(“ART”);// data configuration */

echo “ok”;

?>[/code]

My DB is “i5_articles”. My Table is “ART” and i want to load the column “ARTNUM”.

Hi,

Any idea ? If you need more information, tell me what you want to know.

The client side code is correct, but you need not all includes after connector.js - all those files already a part of dhtmlx.js

On server side, try to use full syntax of render_table command

$conn->render_table("ART", "id", "fieldA, fieldИ, fieldC");

I still have the same error :unamused:

$conn->render_table("ART", "id", "fieldA, fieldB, fieldC");

I don’t understand the parameters…

id, is it the key of my table ?

And fieldA, fieldB, fieldC, are the columns that i want to load in my grid ?

Thank you Stanislav for your help

It works. But i still have a problem with the XML file.

I have a special caracter in the XML file. And this problem prevents the loading of my grid…

Any idea ? I want to change the encoding of the XML file but i don’t know how to do it…

To change encoding, place the next line before render_table command

$conn->set_encoding("iso-88591-1"); //set data encoding here $conn->render_table(...

I did it but my error comes from

<row id='XXXX[b]&[/b]'>

The & is a special character in XML but i can’t modify the DB to change “&” to “&”.

There is a solution ?

Please try to grab the latest version of connector.

github.com/DHTMLX/connector-php/

It must correctly escape special characters in the XML data.

I have the latest version of connector but i still have the error LoadXML.

The “&” in the row id and the “&” in my cell data prevent the loading of my grid.

I don’t know what i must to do…

The only solution I see is to change the character “&” in my DB, but it’s not convenient.

Thanks again for your help Stanislav.

In case of latest version, special chars in the ID field does escaped
github.com/DHTMLX/connector-php … or.php#L90

Please be sure that you are using the latest version of above file.

I took the files the 19/05 and your lastest fix was the 17/03 :question:

It’s strange. I was sure that i have downloaded the lastest version.

Anyway, it works with the above file but now i have the same problem when i want to update my DB with dataprocessor. I searched the file in the link that you gave me but i didn’t find it.

It must be fine with latest version.
Can you enable connectors log and share the log content for the problematic operations