crazy
The snmp part finished, now comes the programming part..
I am trying to connect to a MySQL database and updating a table.
The connecting part is working well, the updating part a bit less. When I am sending a query:
mysql_query("REPLACE INTO TABLE SNMP values('Something','Somethingelse', here i want to pass a variable that is not always an integer)"
The problem here, if the variable is an integer, it works, but if it is a string it does not replace..
Anyone has a idea about this in C language? I can't find anything on that, all in PHP..
thanks again,
Crazy
samer
when you create the column in the table in question, you can define the type of content that it will be hosting.
Make sure it's not INT but TEXT in that case.
crazy
When I am creating the table I am writing:
CREATE TABLE SNMP SERVEUR VARCHAR(50), COMPOSANTE VARCHAR(50), METRIQUE VARCHAR(50), VALEUR VARCHAR(50);
And in my program I am using the replace command as stated in my first post, so I am giving what to write in the first three column, but the fourth I want to pass a variable that can contain character, string or integer. But the only if the variable contains integer it works... and its declared to be varchar which is char but if it contain less than 50, it shrinks it so no memory is more or less lost..
battikh
are you making sure you have the quotes around your variable? if it's a string, i believe mysql needs quotes around it.
crazy
ok,
Let us say the variable I want to pass is:
char var1[50] = "Something here";
mysql_query("REPLACE INTO TABLE SNMP values('Something','Somethingelse', var1)"
if i put 'var1' it will simply write var1, if i don't put the quotes it will write onlt if there is an integer in the array i.e: char var1[50]= "12345";
I want it to write in the database integer or strings or character.
I know in C++ it can be done by mysql_query("REPLACE INTO TABLE SNMP values('Something','Somethingelse', " + var1 + ")"); or something like that, but in C nope..
Crazy
battikh
then the problem is definitely the quotes. it has been a veeeeeeeeeeery long time since i used c, but if my memory is not betraying me again (which i doubt, my memory betrays me so often that i don't trust it anymore), you should use \' instead of '
so it should become something like that:
mysql_query("REPLACE INTO TABLE SNMP values('Something','Somethingelse', \'var1\')"
if this doesn't work, try to put them inside the string:
char var1[50] = "\'Something here\'";
Battikh
crazy
Thanks battikh for the suggestion, I ll try it at work, I think it should be something like that, something with the syntax I mean.