Yesterdayβs MySql Stored Procedures Spatial Tutorial was fully functional for what we wanted to cover on our local MAMP Apache/PHP/MySql web server featuring β¦
- PHP 7 β¦ and β¦
- mysqli_connect() via 5.7.23 β MySQL
β¦ but to offer any version of it βliveβ on rjmprogramming.com.au domain (which we generally try to do for your βreality of purposeβ here at this blog) we came across many issues β¦
- PHP 5 β¦ and β¦
- mysqli_connect() (ie. now the same, ditching the old mysql_connect() ideas) via 5.1.70-cll β MySQL β¦ as well as β¦
- security concerns
Hence yesterdayβs trepidation, huh?! But what makes databases like MySql, especially with its brilliant phpMyAdmin GUI interface, that βstep upβ from other data storage methodologies such as HTTP Cookies or Local Storage or Flat Files is the concept of a βuserβ β¦ yoo, hoo!
The concept of a βuserβ with βdatabasesβ can then team up with concepts such as β¦
- privileges
- role
β¦ in order to add so much more nuance and organization regarding who handles what computing task. Think blogs, for example, and you can have β¦
- administration users (youβll hear βsuperuserβ references) who can achieve all of the functionalities below, and more β¦ versus β¦
- users who just read and never intend to write or comment
- users who want to write blog postings but need administrator help to delete them
- users who want to comment
β¦ and various other βrolesβ. βPrivilegesβ can help the βdatabaseβ decide on what is allowed by a βuserβ to happen on the βdatabaseβ.
Very good and secure βdatabaseβ brands will start very restrictively, maybe on any database starting out with the one administrator βuserβ. To nuance from that position we need the βMySqlβ SQL GRANT command (for allowing, and REVOKE is for the other way around), and weβd like to thank and direct you to the excellent MySql GRANT advice as per β¦
Grant Permissions to MySQL User
The basic syntax for granting permissions is as follows:GRANT permission ON database.table TO βuserβ@βlocalhostβ;
Here is a short list of commonly used permissions :
ALL β Allow complete access to a specific database. If a database is not specified, then allow complete access to the entirety of MySQL.
CREATE β Allow a user to create databases and tables.
DELETE β Allow a user to delete rows from a table.
DROP β Allow a user to drop databases and tables.
EXECUTE β Allow a user to execute stored routines.
GRANT OPTION β Allow a user to grant or remove another userβs privileges.
INSERT β Allow a user to insert rows from a table.
SELECT β Allow a user to select data from a database.
SHOW DATABASES- Allow a user to view a list of all databases.
UPDATE β Allow a user to update rows in a table.
Coming back to our MySql βStored Procedureβ thoughts, itβs that βEXECUTEβ GRANT above that is needed, and yet on our rjmprogramming.com.au domain web server, that idea was restricted. Hence, behind the scenes we detect this with our PHP, and that we MySql GRANT all the DML SQL (the day to day database populating and updating functionalities) of INSERT and UPDATE and SELECT and DELETE, and break the βStored Proceduresβ up into (less cute) sets of DML SQL to achieve the same ends. However, we still present βStored Procedureβ thoughts because β¦
- phpMyAdmin (off cPanel (logged in administratively)) will allow you to create the βStored Proceduresβ
- phpMyAdmin (off cPanel (logged in administratively)) will allow you to EXECUTE the copy and pasted βStored Proceduresβ CALL (too)
As you can see here, the idea of a database (MySql) βuserβ can be a friend to your database βsecurityβ concerns, wouldnβt you say?
Previous relevant MySql Stored Procedures Spatial Tutorial is shown below.
Back when we wrote MySql Stored Procedures Primer Tutorial we wrote it more or less to use β¦
- PHP 5 and its β¦
- mysql_connect()
β¦ MySql database connection logic, but today we have a dual (even trial) purpose in mind (β¦ or βout of mindβ if you were naughty and picked some of those mushrooms out and about at the moment (ie. please donβt)) for todayβs revisit.
- get with the plan of using PHP 7 (as we do with our local MAMP Apache/PHP/MySql web server here) along with mysqli_connect β¦ and β¦
- start you thinking about MySqlβs excellent Spatial Convenience Functions, such as st_distance_sphere() function to determine (in metres) crow fly distances between points (longitude, latitude) on Earth β¦ and β¦
- verify that MySql Stored Procedures havenβt changed as far as arrangements go with all this
So, here is some downloadable PHP programming source code which shows the results of the MySql SQL requests made and can be renamed to thechanged ourmysqlstoredprocedurephp as required.
And here is some downloadable supervisory PHP programming source code which gathers the MySql SQL requests made and can be renamed to thechanged ourmysql_storedprocedurephp as required.
A tad trepidatiously we also offer you todayβs liverun link that we explain more about regarding restrictiveness and its allowances, tomorrow.
You can also see this play out at WordPress 4.1.1βs MySql Stored Procedures Primer Tutorial.
Previous relevant MySql Stored Procedures Primer Tutorial is shown below.
Todayβs tutorial follows up on phpMyAdmin interface to MySql and PHP Primer Tutorial in that we again use the brilliant phpMyAdmin to oversee the results of some PHP code which uses MySql calls to create tables called POINT and CIRCLE used to store information defining a circle, and then it creates three MySql stored procedures in the database to help add circle data with the single MySql statement that goes CALL AddCircle(x, y, radius); via the use of those stored procedures. Letβs see below what Wikipedia says about Stored Procedures generally.
A stored procedure is a subroutine available to applications that access a relational database system. A stored procedure (sometimes called a proc, sproc, StoPro, StoredProc, sp or SP) is actually stored in the database data dictionary.
Typical use for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures can consolidate and centralize logic that was originally implemented in applications. Extensive or complex processing that requires execution of several SQL statements is moved into stored procedures, and all applications call the procedures. One can use nested stored procedures by executing one stored procedure from within another.
Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statement.[1]
Here is some downloadable PHP programming source code which shows the results of the MySql SQL requests made and can be renamed to ourmysqlstoredprocedurephp as required.
Here is some downloadable supervisory PHP programming source code which gathers the MySql SQL requests made and can be renamed to ourmysql_storedprocedurephp as required.
If you want to develop your own live usage (have provided a live usage link here which will not work but you can use if you are a beginner, to get used to mysql errors, which will occur after you hit either button of the link (these errors indicate bad MySql connection details which are the same reason the database dropdown is not full of options), or you can use this link to see the raw MySql SQL involved in piecing this tutorial together) of these two PHP source codes then you could fix up the hard codings for MySql host/username/password up the top of ourmysql_storeprocedure.php (where you may notice that the default host in the code is localhost:8889 which is the default host string for MySql (ie. port 8889 is used) when using a MAMP (Mac laptop) local web server (which uses localhost:8888 as its local βdomain nameβ for http usage)) or you can keep the same code and use a URL like:
[your-domain-name-plus-a-bit-maybe]/ourmysql_storeprocedure.php?host=[your MySql host address]&username=[your MySql username]&password=[your MySql password]&database=[your optional MySql default database name within the looked up list presented]
Previous phpMyAdmin interface to MySql and PHP Primer Tutorial is relevant and shown below.
Transcript:
You never hear much about the data when you hear about great PHP products, but we
all know it is the data that differentiates the quality of the end result.
That is probably because database products like MySql, SqlServer, Oracle SQL, Advantage and Access
are pretty good at what they do, and emphasise reliability rather than flashiness.
MySql and PHP have a great open source interface with phpMyAdmin, which is so good,
you forget that it is not the default MySql administratorβs interface product.
Letβs have a look at this WordPress database and a bit of how it looks, looking
through the prism of phpMyAdmin β¦
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.