Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
MySQL Articles
Page 3 of 355
Which PHP functions are used in the PHP script to fetch data from an existing MySQL table?
PHP provides several functions to fetch data from an existing MySQL table. The most commonly used functions are mysql_query() for executing SQL queries and mysql_fetch_array() for retrieving rows from the result set. mysql_query() Function This function executes an SQL query against a MySQL database and returns a result resource on success or FALSE on failure ? Syntax bool mysql_query( sql, connection ); Parameters Parameter Description sql Required − SQL query to fetch data from an existing MySQL table connection Optional − MySQL connection resource. If not ...
Read MoreHow can we delete an existing MySQL table by using PHP script?
In PHP, you can delete an existing MySQL table using the DROP TABLE SQL statement with PHP's database connection functions. Modern PHP applications should use MySQLi or PDO instead of the deprecated mysql_* functions. Using MySQLi (Procedural) Here's how to delete a MySQL table using MySQLi with proper error handling ? Using PDO PDO provides a more secure and object-oriented approach ? With Safety Check It's good practice to check if the table exists before attempting to delete it ? Key ...
Read MoreWhich PHP function is used to delete an existing database?
PHP uses the mysql_query() function to delete a MySQL database. However, this function is deprecated since PHP 5.5.0 and removed in PHP 7.0.0. Modern PHP applications should use mysqli or PDO instead. Syntax (Legacy) bool mysql_query( sql, connection ); Parameters Parameter Description sql Required. SQL query to delete a MySQL database (DROP DATABASE command) connection Optional. If not specified, the last opened connection by mysql_connect will be used Modern Approach Using MySQLi Here's how to delete a database using the recommended MySQLi extension ? ...
Read MoreWrite an example to establish MySQL database connection using PHP script?
In PHP, you can establish a MySQL database connection using MySQLi or PDO extensions. The old mysql_connect() function is deprecated and should be avoided. Here are modern approaches to connect to MySQL database. Using MySQLi (Procedural) The MySQLi extension provides an interface to access MySQL databases − Using MySQLi (Object-Oriented) The object-oriented approach provides better code organization − Using PDO PDO (PHP Data Objects) provides a database-agnostic interface − Comparison Method Object-Oriented Prepared Statements Database Support ...
Read MoreWhich PHP function is used to disconnect from MySQL database connection?
PHP provides the mysql_close() function to disconnect from a MySQL database connection. This function takes a single parameter, which is a connection resource returned by the mysql_connect() function. Syntax bool mysql_close ( resource $link_identifier ); Here, if a resource is not specified, then the last opened database connection is closed. This function returns true if it closes the connection successfully, otherwise it returns false. Example The following example shows how to connect to and disconnect from a MySQL database − Important Note Deprecated Functions: The mysql_close() function ...
Read MoreHow to Use Go With MongoDB?
MongoDB is a popular NoSQL database that is widely used in modern web applications. Go, on the other hand, is a fast and efficient programming language that is becoming increasingly popular for building web applications. In this article, we will discuss how to use Go with MongoDB, including how to connect to a MongoDB database and how to perform basic CRUD operations. Installing the MongoDB Driver for Go Before we can start using Go with MongoDB, we need to install the MongoDB driver for Go. The easiest way to do this is by using the following command ? ...
Read MoreImplement a query similar to MySQL Union with MongoDB?
To implement a query similar to MySQL UNION in MongoDB, use the $lookup aggregation stage to join collections, followed by $group and $project to combine and format results. This approach joins collections based on matching fields rather than simply concatenating rows. Syntax db.collection1.aggregate([ { $lookup: { from: "collection2", localField: "matchField", foreignField: "matchField", as: "joinedData" ...
Read MoreHow to properly use 'exist' function in MongoDB like in SQL?
To check for existence of a record in MongoDB (similar to SQL's EXISTS function), use findOne() method. This returns the first matching document if it exists, or null if no document matches the query criteria. Syntax db.collection.findOne({ field: "value" }) Sample Data db.existsAlternateDemo.insertMany([ { "StudentName": "Chris" }, { "StudentName": "Chris", "StudentAge": 21 }, { "StudentName": "Chris", "StudentAge": 22, "StudentCountryName": "US" } ]); { "acknowledged": true, "insertedIds": [ ...
Read MoreMySQL Recursive CTE (Common Table Expressions)
A Recursive CTE (Common Table Expression) is a subquery that references itself using its own name. It is defined using WITH RECURSIVE and must have a terminating condition. Recursive CTEs are useful for generating series, traversing hierarchical data, and graph traversals. Syntax WITH RECURSIVE cte_name (col1, col2, ...) AS ( -- Non-recursive (base case): initial rows SELECT col1, col2 FROM table_name UNION ALL -- Recursive case: references cte_name SELECT col1, col2 FROM cte_name WHERE condition ) SELECT ...
Read MoreMySQL PARTITION BY Clause
The PARTITION BY clause in MySQL groups rows into separate partitions (windows) for use with window functions like RANK(), DENSE_RANK(), LEAD(), and LAG(). It must always be used inside an OVER() clause. If omitted, the entire table is treated as a single partition. Syntax window_function(expression) OVER (PARTITION BY column_name [ORDER BY column_name] [frame_clause]) Example Consider a Hacker table ? CREATE TABLE Hacker ( h_id INT, h_name VARCHAR(50), challenge_id INT, score INT ); INSERT INTO Hacker ...
Read More