Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using MySQL 1

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello, since the search engine for the forums are down now, I can not search to see if something similar to this has been posted yet. Sorry in advance if this is a question that has been answered a lot.

Ok, I want to be able to perform mysql queries via C/C++. I have downloaded the mysql API from and have run the examples, but have not been able to understand them.

I know how to program in PHP/Perl using mysql, so I know SQL/the logic behind it, I just need some examples of syntax.

If anyone has a quick demo that they could show me, I would be very appreciative.

Thank you.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Take a look at thread205-113862 , its just a generic sample code using sql.h and the odbc driver properly configured bluenote@uyuyuy.com
(excuse my english)
 
Hello.

Thanks for that. I tried that code out, and it did not work. Nonetheless, I got an example to work. If anyone needs one, here it is:

[tt]
#include <stdio.h>
#include <mysql.h>


#define host &quot;localhost&quot;
#define username &quot;username&quot;
#define password &quot;password&quot;
#define database &quot;database&quot;

MYSQL *conn;
int main()
{
conn = mysql_init(NULL);
mysql_real_connect(conn,host,username,password,database,0,NULL,0);

MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int j;

mysql_query(conn,&quot;SELECT * FROM users WHERE userid=1&quot;);
res_set = mysql_store_result(conn);

unsigned int numrows = mysql_num_rows(res_set);

while ((row = mysql_fetch_row(res_set)) != NULL)
{
for (j=0; j<mysql_num_fields(res_set); j++)
{
printf(&quot;%s\n&quot;,row[j] != NULL ? row[j] : &quot;NULL&quot;);
}
}

mysql_close(conn);
return 0;
}
[/tt] vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top