使用PHP和C#与MySQL交互
问题描述:
我想使用PHP和C#插入,更新和读取数据,是否有一个库可以执行此操作,如果没有人有任何信息可以帮助我,通过一些实验我得到了这个工作:
示例1:我设法使用PHP和C进行总结工作#
PHP代码:
I want to insert, update and read data using PHP and C#, is there a library to do this, if not does anyone have any information to help me along, with some experimenting I got this to work:
Example 1: I managed to get a sum working using PHP and C#
PHP Code:
<?php echo (int)$_GET["a"] + (int)$_GET["b"]; ?>
C#代码:
C# Code:
using (var client = new WebClient())
{
var a = 50;
var b = 100;
var result = client.DownloadString(string.Format("http://antivurusdownload.co.uk/test/csharptest.php?a={0}&b={1}", a, b));
Console.WriteLine(result);
Console.ReadKey();
}
现在我尝试使用此代码将此应用于MySQL,但没有成功
PHP代码:
Now I tried to apply this to MySQL using this code to no success
PHP Code:
<?php
$username="testing123";
$password="helloworld";
$joindate="21/10/2013 - 21:00";
$active=1;
$con=mysqli_connect("localhost","root","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO user (username, password, joindate, active) VALUES ($username, $password, $joindate, $active)");
mysqli_close($con);
?>
任何人都可以帮忙!?谢谢!
Can anyone help!? Thanks!
答
_GET [ a] +(int)
_GET["a"] + (int)
_GET [ b]; ?>
_GET["b"]; ?>
C#代码:
C# Code:
using (var client = new WebClient())
{
var a = 50;
var b = 100;
var result = client.DownloadString(string.Format("http://antivurusdownload.co.uk/test/csharptest.php?a={0}&b={1}", a, b));
Console.WriteLine(result);
Console.ReadKey();
}
现在我尝试使用此代码将此应用于MySQL,但没有成功
PHP代码:
Now I tried to apply this to MySQL using this code to no success
PHP Code:
<?php
username = testing123;
username="testing123";