How can I connect to a database using Project Maker?

  • Автор темы Автор темы nitin2003
  • Дата начала Дата начала

nitin2003

Client
Регистрация
18.09.2012
Сообщения
195
Реакции
11
Баллы
18
Hi,

I want to connect to a database and read/write some data to the tables. How can I connect and read/write data from a database if I am creating a template in Project maker and not code creator?

Thanks
 
Use C# code for it.

Download the .Net Connector and install. You will need to reference the MySql.Data.dll that it installs in the GAC.

Then to connect, throw this into a C# action....

Код:
Развернуть Свернуть Копировать
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
string myConnectionString;

myConnectionString = "server=localhost;uid=[COLOR="#FF0000"]USERNAME[/COLOR];" +
    "pwd=[COLOR="#FF0000"]PASSWORD[/COLOR];database=[COLOR="#FF0000"]DATABASENAME[/COLOR];";

try
{
    conn = new MySql.Data.MySqlClient.MySqlConnection();
    conn.ConnectionString = myConnectionString;
    conn.Open();
	
	cmd = new MySql.Data.MySqlClient.MySqlCommand();
          cmd.Connection = conn;
          cmd.CommandText = "INSERT INTO Authors(Name) VALUES(@Name)";
          cmd.Prepare();
           
          cmd.Parameters.AddWithValue("@Name", "Trygve Gulbranssen");
          cmd.ExecuteNonQuery();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
    return(ex.Message);
}

Of course this is an example of inputting a record into the table. Your queries will vary depending on what you need.
 
Thanks, I will try this.
Use C# code for it.

Download the .Net Connector and install. You will need to reference the MySql.Data.dll that it installs in the GAC.

Then to connect, throw this into a C# action....

Код:
Развернуть Свернуть Копировать
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
string myConnectionString;

myConnectionString = "server=localhost;uid=[COLOR="#FF0000"]USERNAME[/COLOR];" +
    "pwd=[COLOR="#FF0000"]PASSWORD[/COLOR];database=[COLOR="#FF0000"]DATABASENAME[/COLOR];";

try
{
    conn = new MySql.Data.MySqlClient.MySqlConnection();
    conn.ConnectionString = myConnectionString;
    conn.Open();
	
	cmd = new MySql.Data.MySqlClient.MySqlCommand();
          cmd.Connection = conn;
          cmd.CommandText = "INSERT INTO Authors(Name) VALUES(@Name)";
          cmd.Prepare();
           
          cmd.Parameters.AddWithValue("@Name", "Trygve Gulbranssen");
          cmd.ExecuteNonQuery();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
    return(ex.Message);
}

Of course this is an example of inputting a record into the table. Your queries will vary depending on what you need.
 
I didn't work for me. I even removed the tags etc..

Ok I did this:

0io0zIM.jpg


And now it seems to work:

K30yGBK.jpg


but nothing changes on my mysql table... Any clue?
 
Последнее редактирование:
Never mind, it started working oO
 
Did you remember to turn on your Wampserver? lol. Done it plenty of times.
 
Will it support PHP as well ?
 
Ok I have this:
A5Dckwx.jpg


On ProjectMaker, when I run my project manually step by step, this works:

K30yGBK.jpg


BUT, when I let my project run to breakpoint (run everything automatically), it doesn't work.. Zenno says that the Own C# code was executed successfully, but nothing changes on my mysql table.

So, in summary:

Play step by step manually = works, mysql table is changed.
Let Zenno play step by step automatically until breakpoint = doesn't work, mysql table is not changed.

Help?????????
 
I using simple php form for connecting my local mysql, without C#, above form i can read or put values .
 
Aleksandar is right. When connecting with remote databases it is easier to use a simple php page.
 
Yes, but for remote acces is important to have alow permision of server admin . If someone have some service and must put information to mysql of client, he can send client one page to put in root and fill with acces data of mysql, ( like wordpress instalation) in this case client and all service not need have permision for remote acces to mysql, becouse zenno go to custom page on client server.
This option have many solution. Example for tube porn poster, i first creating template for each script, this is pain, but with this custom page, you need only names of tables and all job is done.
 
Последнее редактирование:
This is working for me so far:

index.html:
Код:
Развернуть Свернуть Копировать
<html>
<body>

<form action="insert.php" method="post">
Account: <input type="text" name="account">
Status: <input type="text" name="status">
<input type="submit">
</form>

</body>
</html>

insert.php:
Код:
Развернуть Свернуть Копировать
<?php

$host = "1.1.1.1";
$user = "root";
$pass = "password";
$database = "db_0001";
$conn = mysql_connect($host, $user, $pass) or die( mysql_error() );
        mysql_select_db($database) or die( mysql_error() );

$account = mysql_real_escape_string( $_POST["account"] );
$status = mysql_real_escape_string( $_POST["status"] );


$sql = "UPDATE accounts_table SET status = '{$status}' WHERE account = '{$account}'";

$result = mysql_query( $sql ) or die( mysql_error() );
header("Location: index.html");

?>
 
And simplier:

<?php
$con=mysqli_connect("localhost","root","","wordpress");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"INSERT INTO wp_posts (post_content)
VALUES ('valuefordb')");



mysqli_close($con);
?>

in html field put " post_content " like variable . You can expand wp_posts (post_content) put more variables:
wp_posts (post_content,post_title)

And in
VALUES ('valuefordb,valuefortitle')
 
  • Спасибо
Реакции: V Munich

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)