• VB.net MySQL DB Query
    49 replies, posted
Hi, I've got a php page where I can connect to the DB through Visual Basic, But I'm having trouble being able to do queries. I want it so I can query for Firstname and lastname through a visual basic program. I'm pretty sure I need to use HTTP post, Anyone have any experience in this? Thanks
[QUOTE=Arnold;28325035]I want it so I can query for Firstname and lastname through a visual basic program.[/QUOTE] So you want to display the data a query gives you? It would probably be better to find a way for MySQL to talk to VB directly rather then mess with PHP for the query.
Don't do what benjojo says, talking with MySQL directly with VB is a horrible idea, as your program can easily be reverse-engineered, and there goes your MySQL details. [editline]3rd March 2011[/editline] Ah well I guess you're both perma-banned. Oh well other people reading this will still know.
OP is perma'd but if anyone else is interested. [code] Imports MySql.Data.MySqlClient Dim m_DatabaseConnection As MySqlConnection = New MySqlConnection("server=MYSQLSERVER; user id=USERNAME; password=PASSWORD; database=DATABASE; pooling=false;") Dim SQLDataAdapter As MySqlDataAdapter Dim SQLDataSet As DataSet Dim strSQL As String strSQL = "SELECT * FROM table WHERE Field1 = 'Value';" SQLDataAdapter = New MySqlDataAdapter(strSQL, m_DatabaseConnection) SQLDataSet = New DataSet() SQLDataAdapter.Fill(SQLDataSet) For Each row as DataRow in SQLDataSet.Tables(0).Rows Console.WriteLine(row.item("Field1")) Console.WriteLine(row.item("Field2")) Console.WriteLine(row.item("Field3")) Next m_DatabaseConnection.Close() [/code]
Just have a user with read only permissions, MD5 passwords, etc. If it's set up correctly a cracker couldn't do anything.
[QUOTE=CarlBooth;28404516]OP is perma'd but if anyone else is interested. -code-[/QUOTE] Perfect example of what NOT to do in your programs.
And why is that?
[QUOTE=Apple Pi;28392787]Don't do what benjojo says, talking with MySQL directly with VB is a horrible idea, as your program can easily be reverse-engineered, and there goes your MySQL details.[/QUOTE] That's why
Ok, so instead of being a troll why don't you explain what you think is the correct way to do it.
I'm not trolling. What you should do is have some remote PHP file dealing with all of the database information so there's no chance of it getting hijacked.
[QUOTE=Apple Pi;28435627]I'm not trolling. What you should do is have some remote PHP file dealing with all of the database information so there's no chance of it getting hijacked.[/QUOTE] what if it's a server app do I still have to run it through a dumb php script? you're telling people it's [b]always[/b] a bad idea to access mysql directly, and that is a lie.
You'd never hard-code a Username / Password anyway, you'd store them in a config file for flexibility. If you needed to you could even encrypt the config file.
[QUOTE=Catdaemon;28435907]what if it's a server app do I still have to run it through a dumb php script? you're telling people it's [b]always[/b] a bad idea to access mysql directly, and that is a lie.[/QUOTE] If you're giving your program to other people it's a bad idea. [editline]5th March 2011[/editline] I kinda figured you guys would realize that considering I said "Other people could reverse-engineer it"
OK, so let me get this straight; The actual advice you are giving people is to use a PHP script to access databases because you can reverse-engineer .NET applications?
[QUOTE=Apple Pi;28436755]If you're giving your program to other people it's a bad idea. [editline]5th March 2011[/editline] I kinda figured you guys would realize that considering I said "Other people could reverse-engineer it"[/QUOTE] For a start, you would never hardcode a username and password. Applications that are for a generic purpose, such as managing a MySQL database, would you run them through a PHP script? Futhermore, if this was running on a server would you still connect to a PHP script? (No.)
[QUOTE=SteveUK;28436895]For a start, you would never hardcode a username and password. Applications that are for a generic purpose, such as managing a MySQL database, would you run them through a PHP script? Futhermore, if this was running on a server would you still connect to a PHP script? (No.)[/QUOTE] For a start, what I am trying to say is that people shouldn't be connecting to databases through their script if other people are going to use it (Steam wouldn't connect to a database directly, now would they?), whether or not you hardcore it or use an external source is irrelevant because you shouldn't be doing it anyways. [quote]Applications that are for a generic purpose, such as managing a MySQL database, would you run them through a PHP script?[/quote] Now you're being a smartass, obviously for certain applications like these you wouldn't. [quote]Futhermore, if this was running on a server would you still connect to a PHP script? (No.)[/quote] I believe I've stated this in a previous reply made by myself. Please read the replies. Furthermore, I also believe I've stated multiple times that you shouldn't hide your database information in your program if you're giving it to other people.
So what would you do then.
The OP has not once stated what he wanted to do with his program and you're clearly making a bunch of assumptions.
[QUOTE=CarlBooth;28438599]So what would you do then.[/QUOTE] Depending on circumstances I would use a PHP page. I would also like to point out that PHP pages are [b]significantly[/b] faster than talking with MySQL directly through VB. Carl, what you posted works, but it's slow and has almost no security. Of course if you're making a program that edits MySQL / whatever then sure you'd have to talk directly with it. [QUOTE=SteveUK;28438601]The OP has not once stated what he wanted to do with his program and you're clearly making a bunch of assumptions.[/QUOTE] He stated he wanted to talk with MySQL directly with VB, he clearly states in his first sentence that he's using a PHP at first, but is having trouble doing the queries, and that is when I told him that talking with MySQL directly through VB is a horrible idea. It's quite obvious he's not making a program that edits MySQL databases because he was using PHP at first. If anybody here is making assumptions it's you.
[QUOTE=Apple Pi;28438686]I would also like to point out that PHP pages are [b]significantly[/b] faster than talking with MySQL directly through VB. .[/QUOTE] are you kidding
[QUOTE=Apple Pi;28438686] PHP pages are [b]significantly[/b] faster than talking with MySQL directly through VB. [/QUOTE] How is VB > HTTP GET > PHP Page > MySQL Lib > Database faster than VB > MySQL Lib > Database
Because PHP pages usually have the databases located on localhost, so no actual connecting, whereas with the VB Lib you'd have to connect remotely to the database. HTTP GET is like, what, a few milliseconds? Would create no real noticeable time stretch. I've wrote an entire application out of VB using the MySQL Lib a long time ago, and it was extremely slow. I decided to convert it to use PHP pages entirely and I would say it was about 60% faster, 100% more efficient, and 100% safer.
[QUOTE=Apple Pi;28438774]Because PHP pages usually have the databases located on localhost, so no actual connecting, whereas with the VB Lib you'd have to connect remotely to the database. HTTP GET is like, what, a few milliseconds? Would create no real noticeable time stretch. I've wrote an entire application out of VB using the MySQL Lib a long time ago, and it was extremely slow. I decided to convert it to use PHP pages entirely and I would say it was about 60% faster, 100% more efficient, and 100% safer.[/QUOTE] PHP has to establish a connection [b]in addition[/b] to loading and compiling php code over [b]another[/b] connection. your vb was slower? maybe you just can't code for shit.
[QUOTE=Apple Pi;28438774]Because PHP pages usually have the databases located on localhost, so no actual connecting, whereas with the VB Lib you'd have to connect remotely to the database. HTTP GET is like, what, a few milliseconds? Would create no real noticeable time stretch. I've wrote an entire application out of VB using the MySQL Lib a long time ago, and it was extremely slow. I decided to convert it to use PHP pages entirely and I would say it was about 60% faster, 100% more efficient, and 100% safer.[/QUOTE] I use MySQL and .NET connector on a daily basis at work and I can see you clearly have no idea what you're talking about.
[QUOTE=Catdaemon;28438795]PHP has to establish a connection [b]in addition[/b] to loading and compiling php code over [b]another[/b] connection. your vb was slower? maybe you just can't code for shit.[/QUOTE] Compiling is a few milliseconds [editline]5th March 2011[/editline] [QUOTE=CarlBooth;28438822]I use MySQL and .NET connector on a daily basis at work and I can see you clearly have no idea what you're talking about.[/QUOTE] Or you're just too lazy to actually make a PHP page and test how much faster it is.
[QUOTE=Apple Pi;28438837]Compiling is a few milliseconds [editline]5th March 2011[/editline] Or you're just too lazy to actually make a PHP page and test how much faster it is.[/QUOTE] I don't have to build a rowing boat to know it's slower than a jet ski.
[QUOTE=Apple Pi;28438837]Compiling is a few milliseconds[/QUOTE] Yeah, but establishing a TCP connection is less (guess what you have to do to query a php script???).
[QUOTE=CarlBooth;28438865]I don't have to build a rowing boat to know it's slower than a jet ski.[/QUOTE] Then why are you saying VB is as fast as PHP? [editline]5th March 2011[/editline] [QUOTE=Catdaemon;28438868]Yeah, but establishing a TCP connection is less (guess what you have to do to query a php script???).[/QUOTE] Make an HTTP connection which is another few milliseconds edit: I mean why are you saying connecting to MySQL with VB is as fast as PHP?
[QUOTE=Apple Pi;28438877] Make an HTTP connection which is another few milliseconds[/QUOTE] Which is the same amount (if not less!) milliseconds than connecting to mySQL! Looks like [b]you have absolutely no idea what you're talking about[/b] please stop posting on this or similar topics forever.
[QUOTE=Catdaemon;28438938]Which is the same amount (if not less!) milliseconds than connecting to mySQL! Looks like [b]you have absolutely no idea what you're talking about[/b] please stop posting on this or similar topics forever.[/QUOTE] Guess I'll have to make a comparison chart showing speeds of direct MySQL and PHP MySQL.
Sorry, you need to Log In to post a reply to this thread.