Page 1 of 1

sql in livecode Username

Posted: Mon Nov 15, 2021 5:06 pm
by Samuele
hi, how can i check from livecode if in the table UserName (of an Mysql database) there is already a record like that?
thanks!

Re: sql in livecode Username

Posted: Mon Nov 15, 2021 8:32 pm
by Klaus
That is more a SQL question. :D
What is the name of the database field you need to check?

Re: sql in livecode Username

Posted: Tue Nov 16, 2021 10:12 am
by Samuele
what do you mean in "database field"?

Re: sql in livecode Username

Posted: Tue Nov 16, 2021 10:35 am
by Klaus
A database table has "fields" to store data in.
Example: A table "UserNames" may have these "fields": name, password, age, address
Capisce? :-)

Re: sql in livecode Username

Posted: Tue Nov 16, 2021 6:55 pm
by Samuele
yep, so i need to check the field username of a table Persons

Re: sql in livecode Username

Posted: Tue Nov 16, 2021 7:11 pm
by Klaus
Yep, fetch these data and if they are empty then this name is not yet in the database.

SQL:
select * from UserNames where name = "you name here"

Re: sql in livecode Username

Posted: Wed Nov 17, 2021 11:44 am
by Samuele
yes, that's how i do it on SQL, but how do i tell livecode to do that, in other words how can i write a code on livecode that will check, on SQL, or in other words to make livecode speak with SQL :D
thakns!

Re: sql in livecode Username

Posted: Wed Nov 17, 2021 11:59 am
by Klaus
Take a look at this lesson:
https://lessons.livecode.com/m/4071/l/7 ... l-database

To learn more about the basics of LC, please check these stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html

Re: sql in livecode Username

Posted: Wed Nov 17, 2021 2:14 pm
by Samuele
thanks
Take a look at this lesson:
https://lessons.livecode.com/m/4071/l/7 ... l-database
this i saw already, that's how i started...

Re: sql in livecode Username

Posted: Wed Nov 17, 2021 2:23 pm
by matthiasr
this i saw already, that's how i started...
That lesson contains all needed information to fetch data from a MySQL database.

In short.

1. use revopenDatabase to connect to the DB

2. use revDataFromQuery to fetch the data using your sql statement

3. do whatever you want with the received data

4. use revCloseDatabase to close the database connection again.


Regards,
Matthias

Re: sql in livecode Username

Posted: Wed Nov 17, 2021 10:02 pm
by Samuele
thank you Klaus and matthiasr !

Re: sql in livecode Username

Posted: Thu Nov 18, 2021 10:32 am
by Samuele
hi, this gives me a syntax error any idea why?
select * from UserNames where name = "you name here"
thanks!

Re: sql in livecode Username

Posted: Thu Nov 18, 2021 10:36 am
by matthiasr

Code: Select all

select * from UserNames where name = "you name here"
should be

Code: Select all

select * from UserNames where 'name' = 'you name here'
If i recall correctly then name belongs to the list of MySQL keywords and reserved words.

Btw. if you have phpMyAdmin installed on your webserver you could test your sql statements with that.

phpMyAdmin is a free web app for administration of MySQL Databases. If it is not installed by default on your webserver you can install it.
For me it's a great helper to check/test/debug my sql statements.

Many webservers offer a software installation menu where you can install additional packages. If this is not the case for your web hosting account then you can download phpMyAdmin here
https://www.phpmyadmin.net/downloads/