Sending an email from mySQL Store Procedure - mysql

Can I write a Stored Procedure (or a simple query) in mySQL which can send an email out containing results of a query.
Any help will be useful.

Not without modifications. It has no email-related functions at all. You could write a custom module for it to add such a function, but it seems to me that something like that is in the purview of the application using MySQL, not MySQL itself.

Not directly in MySQL, but I worked on something similar over the weekend.
Background: I wrote an app over the weekend to learn PHP. I knew I would have to be emailing out information from a MySQL database, so I needed a way to send emails with PHP easily, so I integrated PostageApp into my app, which took less than 15 minutes.
Relevant: I wrote a script to pull specific rows in MySQL, and used mysql_fetch_array() to be able to access the information for each of the fields in a row. With the array, I just passed the variables into a PostageApp API call, which used a template that had placeholders for these variables. PostageApp did the rest for me.
Here's how my template in PostageApp looked like:
Hey {{first_name}},
On {{date}}, we noted that you went to {{url}} for the first time.
Of course, not exactly what it is, but those are the variables, that were then passed into the API call.
Let me know if I can help you out with that.
(Full Disclosure: I am the Product Manager of PostageApp. But I actually did build an app over the weekend as a side project.)

Related

Possibility of storing ASP Classic code as a string in MYSQL database [duplicate]

This question already has an answer here:
Execute function stored in a variable
(1 answer)
Closed 10 months ago.
Is it possible to store asp classic code into a MYSQL database and have it execute the code when its pulled? Such as store a variable name into a string and have it execute the ASP before displaying it? I suspect it is either impossible, since the MYSQL request runs after the page is loaded and so the return data will not be execute and will just the variable name. The other thing is it could be an HTML encoding thing where it might be possible to encode it after you pass it to the MYSQL Server, but so far it just reads the variable name. Any ideas on this, is this impossible, or am I derping the encoding somehow:
I have tried using the encoding method like this using a Chr replace function that works elsewhere, but the use of the function is like this:
NEWSTRING = Server.HtmlEncode(OLDSTRING)
With or without the encoding attempt the results just display the ASP Classic code like this:
MESSAGE TO USER <%=Session("var_FOO")%>
Although the Encode doesn't seem to change the string displayed to the screen, the log result shows the encoding attempt, it doesn't put the data in, but converts the character types sort of like this:
"var_Foo"
I may be barking up the wrong tree with the encoding but if you have a hammer you can try smacking some screws until they go in.
This feature has a pin tack in for me at the moment, as a much more simple way is to just store the string in the database as I have been and just add the variables to the string after its pulled instead of putting them into the database. Granted this means the user can't control the error messages with variables tied to it, but meh I think I can live with that.
UPDATE - The similar question offers to do this as a function, and if you read the rest of the post, you will see there are difference, all negative votes are just rage/hate votes. The fact I am UNABLE to delete this post is proof that there are differences, so even S.O. thinks this post is different enough to exist.
Yes, it's possible. Classic ASP offers Eval, Execute, and ExecuteGlobal methods, to which you can pass a text string containing source code.
It's dangerous on a public-facing web site to do this; a cybercreep can, if he figures out how to write arbitary code into your database table, destroy, corrupt, or hijack your app. You're not paranoid: highly motivated strangers are actually plotting against you and looking for sites that work this way. Be careful.
Eval(codeText) runs an expression and returns the result. ExecuteGlobal(codeText) runs it as if it were in the top-level context.
Execute(codeText) runs it in the context (the subroutine or function) where you invoke it.

"unconcatenating" a field and pivoting mysql or talend

I am new to mysql and databases in general. I've come across a problem that I can't seem to find a solution too. I'm not sure even how to word the scenario.
Basically I have a concatenated field that I need to take "explode" and make each value its of that field its own row. I'm pulling this data from a daily feed, so this needs to be automated as either a trigger, stored procedure, or scheduled job in Talend. Here is a simplified version of the situation. Please see the "current file format" and the "desired outcome" pics. Sorry- this is my first post here! Any help would be appreciated!
I am using a mysql database. Currently the file is coming in via csv export, but I will be connecting via Talend Open Studio to sync the data. See the links below for and example. Here is a sample.
A precise answer is difficult without seeing your code, and the sample link returns 404 for me. You should be able to do this within Talend. Try using Talend’s tExtractDelimitedFields or tExtractRegexFields commands to achieve the result you want.

NodeJS Emit when a row is added to database table

I am quite new to NodeJS but I've written a few apps (like a chat, real time page updater etc) And I've used mysql to read from my database and emit() information to my webpage, but how can I have nodeJS watch a database table and emit() whenever a row is added?
I have no idea where to start and google didn't produce much results. However there must be an include I can require() that will watch the database in someway.
The answer really isn't a nodejs question, but a mysql question. If mysql itself can tell you ( via an event or log ) that a row was added, nodejs could read and consume that data. Unfortunately, that doesn't seem to be possible, based on this answer. The answer suggests that the only thing you can do with mysql is to poll for new rows.
IF you're in control of inserting the data rows from nodejs itself, there shouldn't be any problem emitting those events after you get the confirmation it wrote, but I do not have enough information on your project to know what constraints you have.
UPDATE: Nice little npm package https://www.npmjs.com/package/live-sql seems to solve your problem I hope

Where to store info besides mysql

My php script pulls about 1000 names from the mysql db on a certain page. These names are used for a javascript autocomplete script.
I think there's a better method to do this. I would like to update the names with a cronjob once a day (php) and store the names locally in a text file? Where else can I store it? It's not sensitive info.
It should be readable and writable to php.
Since you only need the data updated once a day, have a cron-script generate a static json file in some fixed location. Then read this with ajax on the client and make sure it caches it on the client.
Or potentially, generate the file whenever the database is updated (if this is applicable, I don't know your application)
You could try Memcache. But that could be like using a sledge-hammer to crack a nut.
Edit What about storing the data as simple file and let users (JavaScript) download it. Clients would not query the server for every key stroke because they could search for matching values themself. Format could be JSON because it is simple and JavaScript native.
It's unlikely reading from a text file will be much faster than a database query - MySQL already does a lot of caching that should make your query speedy.
If you need to make this query often and performance is a problem often you could consider using a caching module for PHP.
Related
The best way of PHP Caching

MySQL username variable carried over to another file

So I just set this up:
http://www.phpeasystep.com/phptu/6.html
It was fairly easy, now I have it redirecting to another page but how can I pull the successful username used?
I'm trying to build a basic chat program to learn with.
Getting this would solve how I will add the variable when a message is sent off to the mysql database and to verify it was sent by the right person.
I think you are looking for what we commonly call SESSION variables. This type of variable offers persistence over different pages. The api for handling sessions is nice and simple, and in my (personal opinion) session variables can be very handy, and dead simple to put in action.
Especially for tasks like the one you have at hand, keeping messages and usernames and such. You can even pass objects in sessions, if you want to get wild, just serialise and deserialise the data before and after saving it in a $_SESSION var.
Read up the session handling section in php, this should give you a hint on how to tackle your problem.
On a sidenote, though, there are other ways that don't need session variables, since you posted php code I assumed you wanted a php related answer.
Good-luck