MySQL Articles

Page 3 of 355

Which PHP functions are used in the PHP script to fetch data from an existing MySQL table?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 249 Views

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 More

How can we delete an existing MySQL table by using PHP script?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 302 Views

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 More

Which PHP function is used to delete an existing database?

vanithasree
vanithasree
Updated on 15-Mar-2026 186 Views

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 More

Write an example to establish MySQL database connection using PHP script?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 220 Views

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 More

Which PHP function is used to disconnect from MySQL database connection?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 342 Views

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 More

How to Use Go With MongoDB?

Sabid Ansari
Sabid Ansari
Updated on 15-Mar-2026 593 Views

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 More

Implement a query similar to MySQL Union with MongoDB?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 621 Views

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 More

How to properly use 'exist' function in MongoDB like in SQL?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 196 Views

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 More

MySQL Recursive CTE (Common Table Expressions)

Mithlesh Upadhyay
Mithlesh Upadhyay
Updated on 14-Mar-2026 4K+ Views

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 More

MySQL PARTITION BY Clause

Mithlesh Upadhyay
Mithlesh Upadhyay
Updated on 14-Mar-2026 9K+ Views

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
Showing 21–30 of 3,547 articles
« Prev 1 2 3 4 5 355 Next »
Advertisements