I would like to run a query that returns the first word only from a particular field, this field has multiple words separated by spaces, I assume I may need to carry out some regex work to accomplish this? I know how to do this using a few ways in PHP but this would best be carried out on the
Tag: php
Getting a PDO query string with bound parameters without executing it
Is it possible to get a query string from a PDO object with bound parameters without executing it first? I have code similar to the following (where $dbc is the PDO object): Currently, this will echo out a SQL statement like: “SELECT * FROM users WHERE username = ?”. However, I would like to have the bound parameter included so
How to resolve ambiguous column names when retrieving results?
I have two tables in my database: NEWS table with columns: id – the news id user – the user id of the author) USERS table with columns: id – the user id I want to execute this SQL: SELECT * …
Loading .sql files from within PHP
I’m creating an installation script for an application that I’m developing and need to create databases dynamically from within PHP. I’ve got it to create the database but now I need to load in …
A script to change all tables and fields to the utf-8-bin collation in MYSQL
Is there a SQL or PHP script that I can run that will change the default collation in all tables and fields in a database? I can write one myself, but I think that this should be something that readily available at a site like this. If I can come up with one myself before somebody posts one, I will
How can I prevent SQL injection in PHP?
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example: $unsafe_variable = $_POST[‘user_input’]; …