How-to articles, tricks, and solutions about SQL

Codeigniter $this->db->get(), how do I return values for a specific row?

The $this->db->get() function in CodeIgniter is used to retrieve data from a database table.

Commands out of sync; you can't run this command now

The "Commands out of sync; you can't run this command now" error in PHP usually occurs when you have called a MySQL function in an incorrect order.

Converting Varchar Value to Integer/Decimal Value in SQL Server

In SQL Server, you can convert a varchar value to an integer or decimal value using the CAST or CONVERT function.

could not extract ResultSet in hibernate

If you are trying to execute a query using Hibernate and are getting an error saying "could not extract ResultSet," it could be due to a few different issues:

Display an array in a readable/hierarchical format

Here is an example of how you could display an array in a readable/hierarchical format in PHP:

Doctrine 2: Update query with query builder

To update an entry in a database using Doctrine's query builder, you can use the update method of the QueryBuilder class.

Getting data posted in between two dates

To get data posted between two dates in PHP, you can use a SQL query with a WHERE clause and the BETWEEN operator.

Hibernate show real SQL

To show the real SQL generated by Hibernate, you can enable the show_sql property in the Hibernate configuration file (hibernate.cfg.xml).

How can I prevent SQL injection in PHP?

There are several ways to prevent SQL injection attacks in PHP.

How to convert java.util.Date to java.sql.Date?

To convert a java.util.Date object to a java.sql.Date object in Java, you can use the java.sql.Date constructor that takes a long value as an argument.

How to get the Query Builder to Output its Raw SQL Query as a String with PHP

If you want to grasp the way of getting a query builder to output its raw SQL query as a string using PHP, then you are in the right place.

How to include a PHP variable inside a MySQL statement

To include a PHP variable inside a MySQL statement, you need to use prepared statements with bound parameters.

How to Prevent SQL Injection in PHP

If you want to learn how to prevent SQL injection in PHP, as well as to get comprehensive information about SQL injections, you are in the right place.

How to print a query string with parameter values when using Hibernate

To print a Hibernate query string with parameter values, you can use the toString() method of the Query interface.

How to properly set up a PDO connection

To set up a PDO connection, you will need to do the following:

How to resolve ambiguous column names when retrieving results?

When retrieving results in PHP and encountering ambiguous column names, you can use table aliases to specify which table the column belongs to.

How to select year and month from the created_at attributes of database table in laravel 5.1?

In Laravel 5.1, you can use the selectRaw method to select the year and month from the created_at attribute of a database table.

How to separate DATE and TIME from DATETIME in MySQL?

You can use the DATE() and TIME() functions to extract the date and time parts of a DATETIME value in MySQL.

How to use php array with sql IN operator?

You can use the implode() function to convert the PHP array into a string of comma-separated values, and then use that string in the SQL query with the IN operator.

Increment value in MySQL update query

To increment a value in a MySQL update query using PHP, you can use the += operator.

Laravel: getting a single value from a MySQL query

To get a single value from a MySQL query in Laravel, you can use the value method on a query builder instance.

PDO with INSERT INTO through prepared statements

To insert data into a database using PDO and prepared statements, you can use the following steps:

php/mySQL on XAMPP: password for phpMyAdmin and mysql_connect different?

The password for accessing phpMyAdmin and the password for connecting to the MySQL server using the mysql_connect() function can be different.

selecting unique values from a column

To select unique values from a column in PHP, you can use the array_unique function.

Send html form data to sql database via php (using mysqli)

To send HTML form data to a SQL database using PHP, you will need to use the mysqli (MySQL Improved) extension in PHP.