help with using sqlx
Hello friends, let me show an example of what I want to do, the library I use is sqlx. I will run a query like this, I will give steamid, if that steamid is found, return; If not, it will insert. I leave the version I made with javascript below, I would appreciate it if you inform me.
const SteamID = '12345'; const Query = `SELECT * FROM players WHERE steam_id = '${SteamID}'`; connection.query(Query, (error, results) => { if (error) { console.log(error.stack); return; } if (results.length > 0) { console.log('Steam ID found.'); } else { const query2 = `INSERT INTO players (steam_id) VALUES ('${SteamID}')`; connection.query(query2, (insertError, insertResults) => { if (insertError) { console.log(insertError.stack); return; } } |
Re: help with using sqlx
Not tested
PHP Code:
|
Re: help with using sqlx
Quote:
|
Re: help with using sqlx
Above code is updated.. authorized should be used opposed to putinserver
|
Re: help with using sqlx
Quote:
|
Re: help with using sqlx
Okay, I solved the error I mentioned, now I have a question. For example, I found the sql data with Steam ID, but I need to get or update other things, for example LastName, can you explain how to do that?
|
Re: help with using sqlx
So you need to query for the SteamID and LastName and if no record exists, insert both fields as a new record?
|
Re: help with using sqlx
Quote:
CREATE TABLE IF NOT EXISTS `players` ( `ID` int NOT NULL AUTO_INCREMENT, `Steam_ID` varchar(32) NOT NULL, `LastName` varchar(32) DEFAULT 'None', PRIMARY KEY (`ID`) ) ENGINE=MyISAM AUTO_INCREMENT=421 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; |
Re: help with using sqlx
PHP Code:
|
Re: help with using sqlx
Quote:
PHP Code:
PHP Code:
Then in the call back function, this will retrieve the LastName value. PHP Code:
PHP Code:
PHP Code:
|
| All times are GMT -4. The time now is 00:32. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.