PHP Articles

Page 79 of 81

How to write PHP script to fetch data, based on some conditions, from MySQL table?

varma
varma
Updated on 15-Mar-2026 807 Views

To fetch data from a MySQL table based on specific conditions, you use the WHERE clause in your SQL statement combined with PHP database functions. The WHERE clause filters records that meet specified criteria, allowing you to retrieve only the data you need. Using MySQLi (Recommended) Here's a modern approach using MySQLi to fetch records from a table where the author name is 'Sanjay' −

Read More

Which PHP function is used to release cursor memory associated with MySQL result?

varun
varun
Updated on 15-Mar-2026 253 Views

PHP uses mysql_free_result() function to release the cursor memory associated with MySQL result. This function is part of the original MySQL extension (now deprecated) and returns no value. Syntax mysql_free_result(result); Parameters Parameter Description result Required. Specifies a result set identifier returned by mysql_query(), mysql_store_result() or mysql_use_result() Example Here's how to use mysql_free_result() to free memory after processing a MySQL query result − Modern Alternative Since the original MySQL extension is deprecated, use mysqli_free_result() with MySQLi or PDO instead − ...

Read More

How can we fetch all the data from MySQL table by using mysql_fetch_array() function, returning an array with the numeric index, in PHP script?

Prabhas
Prabhas
Updated on 15-Mar-2026 790 Views

The function mysql_fetch_array() returns an array with numeric indexes when you use the constant MYSQL_NUM as the second argument. This allows you to access fetched data using numeric indexes like $row[0], $row[1], etc. Syntax mysql_fetch_array($result, MYSQL_NUM) Parameters $result − The result resource returned by mysql_query() MYSQL_NUM − Constant that specifies numeric index array Example In this example, we fetch all records from a table named 'tutorials_tbl' using mysql_fetch_array() with MYSQL_NUM to get numeric indexes − Output Tutorial ID :1 Title: Learn PHP ...

Read More

How can we display all the records from MySQL table with the help of PHP script?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 1K+ Views

To display all records from a MySQL table using PHP, you need to establish a database connection, execute a SELECT query, and fetch the results. Below is an example using modern PHP and MySQLi extension ? Using MySQLi Extension The following example demonstrates fetching all records from a table named tutorials_tbl ? Using PDO Extension Alternatively, you can use PDO (PHP Data Objects) for better security and flexibility ? Key Points When fetching data from MySQL with PHP, remember these important points ? fetch_assoc() ...

Read More

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 239 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 291 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 177 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 210 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 334 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

What are the differences between JavaScript and PHP cookies?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 886 Views

Cookies are text files stored on the client's browser to remember user information across web pages. Both JavaScript and PHP can work with cookies, but they operate differently − JavaScript handles cookies on the client-side while PHP manages them on the server-side. JavaScript Cookies JavaScript cookies are manipulated directly in the browser using the document.cookie property. They're ideal for client-side data storage and immediate user interactions. Setting a Cookie with JavaScript // Set a cookie that expires in 7 days document.cookie = "username=john; expires=" + new Date(Date.now() + 7*24*60*60*1000).toUTCString() + "; path=/"; Reading ...

Read More
Showing 781–790 of 802 articles
Advertisements