PHP database name

Hello,
could someone tell me where in the php connector files is the name of the database to which I connect? I’m trying to load options in a combo…

Thanks in advance for any comments!
Marco

When you are creating connector, you are providing db connection object to it. You can use any necessary API to select the necessary database and after that provide the connection object to the connector.

In default code it looks as

[code] $conn = mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db); //selecting database

$data = new DataViewConnector($conn);

[/code]

Thanks a lot!!
I was on the right track, but I have a problem with the require_once statement. Here is my code:

<?php
    echo "Hello1";
    require_once("php/combo_connector.php");
    echo "Hello2";
    $conn=mysql_connect("localhost","root","");
    mysql_select_db("db_name");
    $data = new ComboConnector($conn);
    $data->render_sql("SELECT * FROM `table`","Id","Desc");
    echo "Hello3";
?>

I get to see “Hello1” but not “Hello2”! It gets stuck on the require_once statement and I don’t see anything else! Could you please tell me what I’m doing wrong? How do you define ComboConnector?
Thanks again!
Marco

I have a bit more of information for you:
I moved all my .php file in the root directory and now I think some prossessing in your .php files is being done.
My questions:

  1. what is needed to put the .php file in a folder named php?
  2. I wanted to implement this example:
    docs.dhtmlx.com/doku.php?id=dhtm … ta_from_db
    where can I find the comboOptions.php file?!?
    I’m receiving this error message: “XML or text declaration not at the beginning of an entity”

<?xml version='1.0' encoding='utf-8' ?><complete><option value='1348130098x0'><![CDATA[]]></option> -------------------^
Could you please esplain what this means?
Thanks again,
Marco

As for “Hello3”
You will not see any output after render_ command, as it outputs response and stops further processing.

As for “Hello2” - command itself if valid, check the path - is required file really exist at the target location. Also you can enable error output in php settings, to get more info about the problem

  1. what is needed to put the .php file in a folder named php?
    There is no any special steps or requirements, while paths are valid it must be safe to place them in any folder.

where can I find the comboOptions.php file?!?
In “php connector” package, check samples/combo/01_basic_connector.php

I’m receiving this error message: “XML or text declaration not at the beginning of an entity”
In your php file - check that there is no whitespace before starting <?php tag

Hi Stanislav!
I think the reason for all my troubles is that I’m trying to put a combo inside a form:
If I try to use the form_connector the XML error goes away but I get a bunch of errors when it gets to the form. Probably because the comboOptions.php is not defined…
What is the right connector to use in this case? Do I need to use two connectors? I don’t think so…
Thank you! Sorry to bother you again…
Marco
Ps. At this point I think that the path issue had nothing to do with the problem…

Hello!
I initially had my connector sub in the same HTML file as my form.
This morning I found this post
viewtopic.php?f=19&t=21809&p=69733&hilit=ID+parameter+is+missed#p69733
that has exactly the error I was getting.
This post suggest to have a connector in its own .php file and call il from the connector parameter in the form.
So this is my current situation:

    <script type="text/javascript">
      var myForm, formData;
      function doOnLoad() {
        formData = [
          {type: "calendar", dateFormat: "%d-%m-%Y %H:%i", value: "13-06-2011 11:35", name: "start_date", label: "Start Date", enableTime: true,  calendarPosition: "right"},
          {type: "newcolumn"},
          {type: "calendar", name: "end_date", label: "End Date", value: "02-10-2011",  enableTime: true, dateFormat: "%d-%m-%Y",  calendarPosition: "right"},
          {type: "combo", label: "Trasporto",  name: "trasporto", value: "", connector:"combo_trasporto.php"},
          {type: "button", name: "send", value: "submit"}
        ];
        myForm = new dhtmlXForm("myForm", formData);
        myForm.attachEvent("onButtonClick", function(name) {
            if (name == "send") {
                myForm.send("asp/save_data.asp","post",function(xml){
                  alert("Saved!");
                });
            }
        });
      }
    </script>

and in the combo_trasporto.php I have:

<?php
    echo "Hello ";
    require_once("php/combo_connector.php");
    echo "Hello1";
    $conn=mysql_connect("localhost","root","");
    mysql_select_db("marcatempo");
    echo "Hello2";
    $trasporto = new ComboConnector($conn);
    $trasporto->render_sql("SELECT * FROM `tabella_trasporto`","Id","DescTrasporto");
    echo "Hello3";
?>

Now, I can see my two calendars just fine and the submit button too…
BUT unfortunately the combobox does not show at all… I don’t see any of my "Hello"s inserted for debugging…
Can you see what I’m doing wrong?
Thanks again for your patience!
Marco

You need a connector to load data in form
And you may need a separate connector to load options in select|combo in the form

So there is place for two connectors. One of them is for data, second is for configuration ( as options lists are not linked to the specific data record, but common for all )

comboOptions.php used to load only options, it doesn’t relate to the formconnector in any way.

You can check
dhtmlxForm\samples\06_data\06_combo_options.html

Client side looks good
Server side

  • remove all echo instruction as they will corrupt response xml

BUT unfortunately the combobox does not show at all
Please try to use firebug like tool and check is request to combo_trasporto.php was executed, and that it was a valid xml.

Hello Stanislav!

This did the trick for me!! I was missing dhtmlxform_item_combo.js… This is the reason why I was not seeing any combo!! THANK YOU very much!
Another important point is that you must include the “inputWidth” parameter… for some reason the default is so narrow that you see only one character of the options…

May I please ask you one more thing:
How would you close the connection to a database, but most importantly, where the right place to put it?
Thanks again!!
Marco

I’m sorry, but in the enthusiasm I forgot another very important point for my project…
If you have to show many combos on your form, a few with the same options in the combo but others taking the data from a different table of the database, is this possible?
I tried to make another connector file and run the query on a different table, but I get the same data in both combos… how could this be? Doesn’t the name that you give the combo gets associated with the name in which you put your data in? How does this work then?
Could you help me on this too? :blush:
Many thanks!!
Marco

If you are using php code there is no need for direct connection closing, after script finishing, garbage collector will destroy all not used objects. So connection will be closed automatically after request processing.

Ok, that’s good to know!
Thanks again for all your help…
Marco