MySQL Archive
-
SELECT inside a SELECT
Posted on 27th Jul 2011 | 1 CommentI often forget the exact syntax of things like this… So here’s an example… $query1 = 'SELECT * FROM `'.$dbName.'`.`users` WHERE email NOT IN (SELECT email FROM `'.$setupDBName.'`.`users`)'; -
#1054 – Unknown column in ‘where clause’
Posted on 6th Jul 2011 | No CommentsThe following SQL query causes an error SELECT vote_vo_ip, COUNT(*) as times FROM `vote` LEFT OUTER JOIN `voter` ON vote.vote_vo_id = voter.vo_id WHERE vote_co_id = 2 AND times > 1... -
Export to CSV file
Posted on 6th Jun 2011 | No CommentsThis is something you’re likely to do several times in several different scenarios. The common one for me is generating reports from a database. I tend to build a $_SESSION... -
Full Text Search in MySQL Database
Posted on 21st Apr 2011 | No CommentsI love the ‘LIKE’ SQL command for searching within phpMyAdmin, but to do the job properly on a page, you really need to know how to use ‘Full-text Searching’… This... -
mysql_insert_id()
Posted on 28th Mar 2011 | No CommentsWhen you’ve just added an entry to the database with ‘INSERT’, and you need to get the ID of that row for the next step…. $lastId = mysql_insert_id(); -
My Escape Data Function
Posted on 11th Mar 2011 | No CommentsQuick and handy function to purify data before entering into the database function escape_data($data){ $data = mysql_escape_string(trim($data)); $data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8'); return = $data; } -
mysql_real_escape_string
Posted on 4th Jan 2011 | No CommentsIn a nutshell, it makes a string safe to be entered into a database…. For example: $email = 'myemail@domain.co.uk'; // This could come from a form, etc. $result = mysql_query("SELECT... -
Backup Database with PHP
Posted on 28th Jul 2010 | No CommentsHere’s a great little script that will back-up your database to a zipped .gz file and store it in a folder on your server…. <?php // Set Vars $dbname =... -
Connect To Database With mysqli_connect
Posted on 5th Jul 2010 | No CommentsHere’s another way to connect to the databse: // Connect with username, password, etc... $link = mysqli_connect('localhost', 'userName', 'passWord'); if (!$link){ $error = 'Unable to connect to the database server.';...









