<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>

This is my code in php..i want it in C..any help? what should be written instead of:
'$_POST[firstname]','$_POST[lastname]','$_POST[age]'

Recommended Answers

It is a lot more difficult in C language see ODBC tutorials

Jump to Post

All 2 Replies

With all due respect Ancient Dragon, the best solution to his problem is not ODBC.

ODBC adds additional layers of overhead and configuration complexity to the more obvious solution of linking to the MySQL C library which exposes nearly all the same commands he used in his PHP code.

Here is a link to the MySQL C API reference:

http://dev.mysql.com/doc/refman/5.0/en/c-api-function-overview.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.