Can I make it shorter - MySQL
#1

Hello, I started working to transfer my mode on MySQL
Can I do this shorter ? (Originally from newbienoob's tutorial)
(Registration)
PHP код:
mysql_format(mysqlquerysizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0)"Name[playerid], pInfo[playerid][Password], IP[playerid]); 
I have 345 columns in my .ini and it's too long to write
Can I do this shorter?
Same for loading a character
Reply
#2

Yes if you have default values such as 0, there is no need to set it while registering a new row.
Default values can be set when you are creating a column in a MySQL table, either by code or manually.

For example:
You have default values of `Admin`, `VIP` etc. as 0. So your query can be:
pawn Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES ('%e', '%s', '%s')", Name[playerid], pInfo[playerid][Password], IP[playerid]);
Reply
#3

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Yes if you have default values such as 0, there is no need to set it while registering a new row.
Default values can be set when you are creating a column in a MySQL table, either by code or manually.

For example:
You have default values of `Admin`, `VIP` etc. as 0. So your query can be:
pawn Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES ('%e', '%s', '%s')", Name[playerid], pInfo[playerid][Password], IP[playerid]);
Makes sense indeed, thank you
Regarding player load
How can I load everything without a mass code ?
Example for mass code
PHP код:
pInfo[playerid][Admin] = cache_get_field_content_int(0"Admin"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
     
pInfo[playerid][VIP] = cache_get_field_content_int(0"VIP"); //Above
     
pInfo[playerid][Money] = cache_get_field_content_int(0"Money");//Above
     
pInfo[playerid][posX] = cache_get_field_content_float(0"PosX");//Above. Since player's position is a float, we use cache_get_field_content_float
     
pInfo[playerid][posY] = cache_get_field_content_float(0"PosY");//Above
     
pInfo[playerid][posZ] = cache_get_field_content_float(0"PosZ");//Above 
Edit - in default values on column edition
Shall I put it NULL or otherwise?
Reply
#4

It is by far the only way of loading and is very sophisticated.

Default values can be done like this: (example while creating a table)
"CREATE TABLE `Users` (`Int` INTEGER DEFAULT 0, `String` TEXT DEFAULT 'default text here', `Float` FLOAT DEFAULT 0.0)"

http://www.tutorialspoint.com/sqlite
^^ This website may be helpful.
Reply
#5

Quote:
Originally Posted by Gammix
Посмотреть сообщение
It is by far the only way of loading and is very sophisticated.

Default values can be done like this: (example while creating a table)
"CREATE TABLE `Users` (`Int` INTEGER DEFAULT 0, `String` TEXT DEFAULT 'default text here', `Float` FLOAT DEFAULT 0.0)"

http://www.tutorialspoint.com/sqlite
^^ This website may be helpful.
Thanks
Just to realize the idea of the speed of MySQL
Does the load char executes the catch field all at once to make it fast or ?
And I'll use the website, thanks
Reply
#6

Quote:
Originally Posted by Gammix
Посмотреть сообщение
It is by far the only way of loading and is very sophisticated.

Default values can be done like this: (example while creating a table)
"CREATE TABLE `Users` (`Int` INTEGER DEFAULT 0, `String` TEXT DEFAULT 'default text here', `Float` FLOAT DEFAULT 0.0)"

http://www.tutorialspoint.com/sqlite
^^ This website may be helpful.
Last question
Is it possible to transfer databases
I mean transfer my database from XAMPP to my further VPS
Reply
#7

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Thanks
Just to realize the idea of the speed of MySQL
Does the load char executes the catch field all at once to make it fast or ?
And I'll use the website, thanks
Yes, MySQL loads all the data at once and forward it be only usable in the callback used while executing a threaded query. That's why threaded queries are preferred, because of it's multi task and speed.

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Last question
Is it possible to transfer databases
I mean transfer my database from XAMPP to my further VPS
I have no idea about that.
Reply
#8

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Last question
Is it possible to transfer databases
I mean transfer my database from XAMPP to my further VPS
Yes, it is possible. You'll either have to link in using remote database connection (which is slower) or just download and upload which will be the easiest way.
Reply
#9

You just have to navigate to "Export" button where you can download the whole database in SQL format and then upload it "Import" on your destined phpMyAdmin. Once you've purchased a VPS from OVH, you'll have to install phpMyAdmin all by yourself and after that you'll be able to upload without any issues.
NOTE : There might be memory limit which can be configured through php.ini file.
Reply
#10

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
You just have to navigate to "Export" button where you can download the whole database in SQL format and then upload it "Import" on your destined phpMyAdmin. Once you've purchased a VPS from OVH, you'll have to install phpMyAdmin all by yourself and after that you'll be able to upload without any issues.
NOTE : There might be memory limit which can be configured through php.ini file.
Thanks!

Scripting time xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)